blob: 26fe7922aee9f4066e8e51f5314152013f540d54 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -emit-llvm %s -o %t
Daniel Dunbarc1ab9002009-07-11 20:32:50 +00002
3void p(const char*, ...);
4
5@interface NSArray
6+(NSArray*) arrayWithObjects: (id) first, ...;
7-(unsigned) count;
8@end
9@interface NSString
10-(const char*) cString;
11@end
12
13#define S(n) @#n
14#define L1(n) S(n+0),S(n+1)
15#define L2(n) L1(n+0),L1(n+2)
16#define L3(n) L2(n+0),L2(n+4)
17#define L4(n) L3(n+0),L3(n+8)
18#define L5(n) L4(n+0),L4(n+16)
19#define L6(n) L5(n+0),L5(n+32)
20
21void t0() {
22 NSArray *array = [NSArray arrayWithObjects: L1(0), (void*)0];
23
24 p("array.length: %d\n", [array count]);
25 unsigned index = 0;
Fariborz Jahanianea161102010-08-12 22:25:42 +000026 for (NSString *i in array) { // expected-warning {{collection expression type 'NSArray *' may not respond}}
Daniel Dunbarc1ab9002009-07-11 20:32:50 +000027 p("element %d: %s\n", index++, [i cString]);
28 }
29}
30
31void t1() {
32 NSArray *array = [NSArray arrayWithObjects: L6(0), (void*)0];
33
34 p("array.length: %d\n", [array count]);
35 unsigned index = 0;
Fariborz Jahanianea161102010-08-12 22:25:42 +000036 for (NSString *i in array) { // expected-warning {{collection expression type 'NSArray *' may not respond}}
Daniel Dunbarc1ab9002009-07-11 20:32:50 +000037 index++;
38 if (index == 10)
39 continue;
40 p("element %d: %s\n", index, [i cString]);
41 if (index == 55)
42 break;
43 }
44}
John McCall57b3b6a2011-02-22 07:16:58 +000045
46// rdar://problem/9027663
47void t2(NSArray *array) {
48 for (NSArray *array in array) { // expected-warning {{collection expression type 'NSArray *' may not respond}}
49 }
50}