blob: 26bca189d1f6b4d1444c997422c2202b168b6ead [file] [log] [blame]
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
2// rdar://10111397
3
4#if __LP64__
5typedef unsigned long NSUInteger;
6#else
7typedef unsigned int NSUInteger;
8#endif
9
10@interface NSObject
11+ (NSObject*)nsobject;
12@end
13
14@interface NSNumber : NSObject
15+ (NSNumber *)numberWithChar:(char)value;
16+ (NSNumber *)numberWithInt:(int)value;
17+ (NSNumber *)numberWithFloat:(float)value;
18@end
19
20int main() {
21 NSNumber * N = @3.1415926535; // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}}
22 NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}}
23 NSNumber * NInt = @1000;
24 NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}}
25 id character = @ 'a';
26
27 NSNumber *NNegativeInt = @-1000;
28 NSNumber *NPositiveInt = @+1000;
29 NSNumber *NNegativeFloat = @-1000.1f;
30 NSNumber *NPositiveFloat = @+1000.1f;
31
32 int five = 5;
33 @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}}
34 @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}}
35}
36
37// Dictionary test
38@class NSDictionary;
39
40NSDictionary *err() {
41 return @{@"name" : @"value"}; // expected-error {{declaration of 'dictionaryWithObjects:forKeys:count:' is missing in NSDictionary class}}
42}
43
44@interface NSDate : NSObject
45+ (NSDate *) date;
46@end
47
48@protocol NSCopying
49- copy;
50@end
51
52@interface NSDictionary : NSObject
53+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt;
54@end
55
56@interface NSString<NSCopying>
57@end
58
59id NSUserName();
60
61int Int();
62
63NSDictionary * blocks() {
64 return @{ @"task" : ^ { return 17; } };
65}
66
67NSDictionary * warn() {
68 NSDictionary *dictionary = @{@"name" : NSUserName(),
69 @"date" : [NSDate date],
70 @"name2" : @"other",
71 NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
72 NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}}
73
74 NSObject *o;
75 NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
76 @"date" : [NSDate date] };
77 return dictionary3;
78}
Fariborz Jahanian262acda2012-04-12 21:24:56 +000079
80// rdar:// 11231426
Fariborz Jahanian93a49942012-04-16 21:03:30 +000081typedef float BOOL;
Fariborz Jahanian262acda2012-04-12 21:24:56 +000082
83BOOL radar11231426() {
Fariborz Jahanian93a49942012-04-16 21:03:30 +000084 return __objc_yes;
Fariborz Jahanian262acda2012-04-12 21:24:56 +000085}
Jordy Rose99446d92012-05-12 15:53:41 +000086
87id stringBoxingNoSuchMethod(const char *str) {
88 return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}}
89}