blob: 2971fcc453992fd4d96f1839bf55e81386e0906a [file] [log] [blame]
Ted Kremeneke65b0862012-03-06 20:05:56 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// rdar://10111397
Fariborz Jahaniane1e33f82013-11-01 21:58:17 +00003// 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 Kremeneke65b0862012-03-06 20:05:56 +00005
6#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
7typedef unsigned long NSUInteger;
8#else
9typedef unsigned int NSUInteger;
10#endif
11
Alex Denisov10c45462015-02-17 06:43:10 +000012void checkNSArrayUnavailableDiagnostic() {
13 id obj;
14 id arr = @[obj]; // expected-error {{NSArray must be available to use Objective-C array literals}}
15}
16
17@class NSArray;
18
19void checkNSArrayFDDiagnostic() {
20 id obj;
21 id arr = @[obj]; // expected-error {{declaration of 'arrayWithObjects:count:' is missing in NSArray class}}
22}
23
Ted Kremeneke65b0862012-03-06 20:05:56 +000024@class NSString;
25
26extern 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
45int 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 Jahaniana802c352013-08-13 23:44:55 +000056
57// rdar://14303083
58id Test14303083() {
59 id obj = @[ @"A", (@"B" @"C")];
Fariborz Jahanianfde99b22013-08-14 00:07:10 +000060 return @[ @"A", @"B" @"C"]; // expected-warning {{concatenated NSString literal for an NSArray expression - possibly missing a comma}}
Fariborz Jahaniana802c352013-08-13 23:44:55 +000061}
Ted Kremenek197fee42013-10-09 22:34:33 +000062id 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}