[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / clang / test / SemaObjC / objc-literal-nsnumber.m
blobceb31f8af156a2a05e46cbbd3d8997a3962c2644
1 // RUN: %clang_cc1  -fsyntax-only -fblocks -triple x86_64-apple-darwin10 -verify %s
2 // rdar://10111397
4 #if __LP64__
5 typedef unsigned long NSUInteger;
6 typedef long NSInteger;
7 #else
8 typedef unsigned int NSUInteger;
9 typedef int NSInteger;
10 #endif
12 void checkNSNumberUnavailableDiagnostic() {
13   id num = @1000; // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}
15   int x = 1000;
16   id num1 = @(x); // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}\
17                   // expected-error {{illegal type 'int' used in a boxed expression}}
20 @class NSNumber; // expected-note 2 {{forward declaration of class here}}
22 void checkNSNumberFDDiagnostic() {
23   id num = @1000; // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}
25   int x = 1000;
26   id num1 = @(x); // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}\
27                   // expected-error {{illegal type 'int' used in a boxed expression}}
30 @interface NSObject
31 + (NSObject*)nsobject;
32 @end
34 @interface NSNumber : NSObject
35 + (NSNumber *)numberWithChar:(char)value;
36 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
37 + (NSNumber *)numberWithShort:(short)value;
38 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
39 + (NSNumber *)numberWithInt:(int)value;
40 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
41 + (NSNumber *)numberWithLong:(long)value;
42 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
43 + (NSNumber *)numberWithLongLong:(long long)value;
44 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
45 + (NSNumber *)numberWithFloat:(float)value;
46 + (NSNumber *)numberWithInteger:(NSInteger)value ;
47 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ;
48 @end
50 // rdar://16417427
51 int big = 1391126400;
52 int thousand = 1000;
53 int main() {
54   NSNumber * N = @3.1415926535;  // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}}
55   NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}}
56   NSNumber * NInt = @1000;
57   NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}}
58   id character = @ 'a';
60   NSNumber *NNegativeInt = @-1000;
61   NSNumber *NPositiveInt = @+1000;
62   NSNumber *NNegativeFloat = @-1000.1f;
63   NSNumber *NPositiveFloat = @+1000.1f;
65   int five = 5;
66   @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}}
67   @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}}
68   NSNumber *av = @(1391126400000);
69   NSNumber *bv = @(1391126400 * 1000); // expected-warning {{overflow in expression; result is -443003904 with type 'int'}}
70   NSNumber *cv = @(big * thousand);
73 // Dictionary test
74 @class NSDictionary;  // expected-note {{forward declaration of class here}}
76 NSDictionary *err() {
77   return @{@"name" : @"value"}; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}}
80 @interface NSDate : NSObject
81 + (NSDate *) date;
82 @end
84 @protocol NSCopying
85 - copy;
86 @end
88 @interface NSDictionary : NSObject
89 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt;
90 @end
92 @interface NSString<NSCopying>
93 @end
95 id NSUserName();
97 int Int();
99 NSDictionary * blocks() {
100   return @{ @"task" : ^ { return 17; } };
103 NSDictionary * warn() {
104   NSDictionary *dictionary = @{@"name" : NSUserName(),
105                                @"date" : [NSDate date],
106                                @"name2" : @"other",
107                                NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
108   NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}}
110   NSObject *o;
111   NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
112                                @"date" : [NSDate date] };
113   return dictionary3;
116 // rdar:// 11231426
117 typedef float BOOL;
119 BOOL radar11231426() {
120         return __objc_yes;
123 id stringBoxingNoSuchMethod(const char *str) {
124   return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}}