blob: 91ea2ec4e0d48a03c5b8a063969cfe04a9f38851 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001/* RUN: %clang_cc1 -Wall -fsyntax-only -verify -std=c89 -pedantic %s
Chris Lattner4d00f2a2009-04-22 00:54:41 +00002 */
Anders Carlsson1fe379f2008-08-25 18:16:36 +00003
4@class NSArray;
5
Chris Lattner4d00f2a2009-04-22 00:54:41 +00006void f(NSArray *a) {
7 id keys;
8 for (int i in a); /* expected-error{{selector element type 'int' is not a valid object}} */
9 for ((id)2 in a); /* expected-error{{selector element is not a valid lvalue}} */
10 for (2 in a); /* expected-error{{selector element is not a valid lvalue}} */
11
12 /* This should be ok, 'thisKey' should be scoped to the loop in question,
13 * and no diagnostics even in pedantic mode should happen.
14 * rdar://6814674
15 */
Fariborz Jahanianbdf3d9a2013-07-06 18:04:13 +000016 for (id thisKey in keys); /* expected-warning {{unused variable 'thisKey'}} */
17 for (id thisKey in keys); /* expected-warning {{unused variable 'thisKey'}} */
Chris Lattnerd1625842008-11-24 06:25:27 +000018}
Fariborz Jahanian61478062011-03-09 20:18:06 +000019
20/* // rdar://9072298 */
21@protocol NSObject @end
22
23@interface NSObject <NSObject> {
24 Class isa;
25}
26@end
27
28typedef struct {
29 unsigned long state;
30 id *itemsPtr;
31 unsigned long *mutationsPtr;
32 unsigned long extra[5];
33} NSFastEnumerationState;
34
35@protocol NSFastEnumeration
36
37- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
38
39@end
40
41int main ()
42{
43 NSObject<NSFastEnumeration>* collection = ((void*)0);
Fariborz Jahanianbdf3d9a2013-07-06 18:04:13 +000044 for (id thing in collection) { } /* expected-warning {{unused variable 'thing'}} */
Fariborz Jahanian61478062011-03-09 20:18:06 +000045
46 return 0;
47}
48
John McCall29bbd1a2012-03-30 05:43:39 +000049/* rdar://problem/11068137 */
50@interface Test2
51@property (assign) id prop;
52@end
53void test2(NSObject<NSFastEnumeration> *collection) {
54 Test2 *obj;
55 for (obj.prop in collection) { /* expected-error {{selector element is not a valid lvalue}} */
56 }
57}