1 // RUN: %clang_cc1 -fsyntax-only -fblocks -triple x86_64-apple-darwin10 -verify %s
4 typedef unsigned long NSUInteger;
5 typedef long NSInteger;
7 typedef unsigned int NSUInteger;
11 void checkNSNumberUnavailableDiagnostic(void) {
12 id num = @1000; // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}
15 id num1 = @(x); // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}\
16 // expected-error {{illegal type 'int' used in a boxed expression}}
19 @class NSNumber; // expected-note 2 {{forward declaration of class here}}
21 void checkNSNumberFDDiagnostic(void) {
22 id num = @1000; // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}
25 id num1 = @(x); // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}\
26 // expected-error {{illegal type 'int' used in a boxed expression}}
30 + (NSObject*)nsobject;
33 @interface NSNumber : NSObject
34 + (NSNumber *)numberWithChar:(char)value;
35 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
36 + (NSNumber *)numberWithShort:(short)value;
37 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
38 + (NSNumber *)numberWithInt:(int)value;
39 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
40 + (NSNumber *)numberWithLong:(long)value;
41 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
42 + (NSNumber *)numberWithLongLong:(long long)value;
43 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
44 + (NSNumber *)numberWithFloat:(float)value;
45 + (NSNumber *)numberWithInteger:(NSInteger)value ;
46 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ;
52 NSNumber * N = @3.1415926535; // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}}
53 NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}}
54 NSNumber * NInt = @1000;
55 NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}}
58 NSNumber *NNegativeInt = @-1000;
59 NSNumber *NPositiveInt = @+1000;
60 NSNumber *NNegativeFloat = @-1000.1f;
61 NSNumber *NPositiveFloat = @+1000.1f;
64 @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}}
65 @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}}
66 NSNumber *av = @(1391126400000);
67 NSNumber *bv = @(1391126400 * 1000); // expected-warning {{overflow in expression; result is -443'003'904 with type 'int'}}
68 NSNumber *cv = @(big * thousand);
72 @class NSDictionary; // expected-note {{forward declaration of class here}}
74 NSDictionary *err(void) {
75 return @{@"name" : @"value"}; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}}
78 @interface NSDate : NSObject
86 @interface NSDictionary : NSObject
87 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt;
90 @interface NSString<NSCopying>
97 NSDictionary * blocks(void) {
98 return @{ @"task" : ^ { return 17; } };
101 NSDictionary * warn(void) {
102 NSDictionary *dictionary = @{@"name" : NSUserName(),
103 @"date" : [NSDate date],
105 NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
106 NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}}
109 NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
110 @"date" : [NSDate date] };
116 BOOL radar11231426(void) {
120 id stringBoxingNoSuchMethod(const char *str) {
121 return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}}