Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | // rdar://10111397 |
Fariborz Jahanian | e1e33f8 | 2013-11-01 21:58:17 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -fsyntax-only -triple i386-apple-macosx10.9.0 -fobjc-runtime=macosx-fragile-10.9.0 -fobjc-subscripting-legacy-runtime -verify %s |
| 4 | // rdar://15363492 |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 5 | |
| 6 | #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 |
| 7 | typedef unsigned long NSUInteger; |
| 8 | #else |
| 9 | typedef unsigned int NSUInteger; |
| 10 | #endif |
| 11 | |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 12 | void checkNSArrayUnavailableDiagnostic() { |
| 13 | id obj; |
Alex Denisov | b7d8563 | 2015-07-24 05:09:40 +0000 | [diff] [blame] | 14 | id arr = @[obj]; // expected-error {{definition of class NSArray must be available to use Objective-C array literals}} |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 15 | } |
| 16 | |
Alex Denisov | b7d8563 | 2015-07-24 05:09:40 +0000 | [diff] [blame] | 17 | @class NSArray; // expected-note {{forward declaration of class here}} |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 18 | |
| 19 | void checkNSArrayFDDiagnostic() { |
| 20 | id obj; |
Alex Denisov | b7d8563 | 2015-07-24 05:09:40 +0000 | [diff] [blame] | 21 | id arr = @[obj]; // expected-error {{definition of class NSArray must be available to use Objective-C array literals}} |
Alex Denisov | 10c4546 | 2015-02-17 06:43:10 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 24 | @class NSString; |
| 25 | |
| 26 | extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); |
| 27 | |
| 28 | @class NSFastEnumerationState; |
| 29 | |
| 30 | @protocol NSFastEnumeration |
| 31 | |
| 32 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id [])buffer count:(NSUInteger)len; |
| 33 | |
| 34 | @end |
| 35 | |
| 36 | @interface NSNumber |
| 37 | + (NSNumber *)numberWithInt:(int)value; |
| 38 | @end |
| 39 | |
| 40 | @interface NSArray <NSFastEnumeration> |
| 41 | + (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; |
| 42 | @end |
| 43 | |
| 44 | |
| 45 | int main() { |
| 46 | NSArray *array = @[@"Hello", @"There", @"How Are You", [NSNumber numberWithInt:42]]; |
| 47 | |
| 48 | for (id string in array) |
| 49 | NSLog(@"%@\n", string); |
| 50 | |
| 51 | NSArray *array1 = @["Forgot"]; // expected-error {{string literal must be prefixed by '@' in a collection}} |
| 52 | |
| 53 | const char *blah; |
| 54 | NSArray *array2 = @[blah]; // expected-error{{collection element of type 'const char *' is not an Objective-C object}} |
| 55 | } |
Fariborz Jahanian | a802c35 | 2013-08-13 23:44:55 +0000 | [diff] [blame] | 56 | |
| 57 | // rdar://14303083 |
| 58 | id Test14303083() { |
| 59 | id obj = @[ @"A", (@"B" @"C")]; |
Fariborz Jahanian | fde99b2 | 2013-08-14 00:07:10 +0000 | [diff] [blame] | 60 | return @[ @"A", @"B" @"C"]; // expected-warning {{concatenated NSString literal for an NSArray expression - possibly missing a comma}} |
Fariborz Jahanian | a802c35 | 2013-08-13 23:44:55 +0000 | [diff] [blame] | 61 | } |
Ted Kremenek | 197fee4 | 2013-10-09 22:34:33 +0000 | [diff] [blame] | 62 | id radar15147688() { |
| 63 | #define R15147688_A @"hello" |
| 64 | #define R15147688_B "world" |
| 65 | #define CONCATSTR R15147688_A R15147688_B |
| 66 | id x = @[ @"stuff", CONCATSTR ]; // no-warning |
| 67 | x = @[ @"stuff", @"hello" "world"]; // expected-warning {{concatenated NSString literal for an NSArray expression}} |
| 68 | return x; |
| 69 | } |
Bruno Cardoso Lopes | 1383ddc | 2016-07-19 20:21:18 +0000 | [diff] [blame] | 70 | |
| 71 | enum XXXYYYZZZType { XXXYYYZZZTypeAny }; // expected-note {{'XXXYYYZZZTypeAny' declared here}} |
| 72 | void foo() { |
| 73 | NSArray *array = @[ |
| 74 | @(XXXYYYZZZTypeA), // expected-error {{use of undeclared identifier 'XXXYYYZZZTypeA'; did you mean 'XXXYYYZZZTypeAny'}} |
| 75 | @(XXXYYYZZZTypeSomethingSomething) // expected-error {{use of undeclared identifier 'XXXYYYZZZTypeSomethingSomething'}} |
| 76 | ]; |
| 77 | } |