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