• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1  -fsyntax-only -fblocks -triple x86_64-apple-darwin10 -verify %s
2// rdar://10111397
3
4#if __LP64__
5typedef unsigned long NSUInteger;
6typedef long NSInteger;
7#else
8typedef unsigned int NSUInteger;
9typedef int NSInteger;
10#endif
11
12void checkNSNumberUnavailableDiagnostic() {
13  id num = @1000; // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}
14
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}}
18}
19
20@class NSNumber; // expected-note 2 {{forward declaration of class here}}
21
22void checkNSNumberFDDiagnostic() {
23  id num = @1000; // expected-error {{definition of class NSNumber must be available to use Objective-C numeric literals}}
24
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}}
28}
29
30@interface NSObject
31+ (NSObject*)nsobject;
32@end
33
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
49
50// rdar://16417427
51int big = 1391126400;
52int thousand = 1000;
53int 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';
59
60  NSNumber *NNegativeInt = @-1000;
61  NSNumber *NPositiveInt = @+1000;
62  NSNumber *NNegativeFloat = @-1000.1f;
63  NSNumber *NPositiveFloat = @+1000.1f;
64
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);
71}
72
73// Dictionary test
74@class NSDictionary;  // expected-note {{forward declaration of class here}}
75
76NSDictionary *err() {
77  return @{@"name" : @"value"}; // expected-error {{definition of class NSDictionary must be available to use Objective-C dictionary literals}}
78}
79
80@interface NSDate : NSObject
81+ (NSDate *) date;
82@end
83
84@protocol NSCopying
85- copy;
86@end
87
88@interface NSDictionary : NSObject
89+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt;
90@end
91
92@interface NSString<NSCopying>
93@end
94
95id NSUserName();
96
97int Int();
98
99NSDictionary * blocks() {
100  return @{ @"task" : ^ { return 17; } };
101}
102
103NSDictionary * 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}}
109
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;
114}
115
116// rdar:// 11231426
117typedef float BOOL;
118
119BOOL radar11231426() {
120        return __objc_yes;
121}
122
123id stringBoxingNoSuchMethod(const char *str) {
124  return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}}
125}
126