1/* RUN: %clang_cc1 -Wall -fsyntax-only -verify -std=c89 -pedantic %s 2 */ 3 4@class NSArray; 5 6void 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 */ 16 for (id thisKey in keys); /* expected-warning {{unused variable 'thisKey'}} */ 17 for (id thisKey in keys); /* expected-warning {{unused variable 'thisKey'}} */ 18} 19 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); 44 for (id thing in collection) { } /* expected-warning {{unused variable 'thing'}} */ 45 46 return 0; 47} 48 49/* 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} 58 59int cond(); 60 61void test3(NSObject<NSFastEnumeration> *a0, NSObject<NSFastEnumeration> *a1) { 62 for (id i in a0) { /* expected-note 2 {{jump enters Objective-C fast enumeration loop}} */ 63 for (id j in a1) { /* expected-note 2 {{jump enters Objective-C fast enumeration loop}} */ 64 (void)i, (void)j; 65label0: 66 if (cond()) 67 goto label1; 68 } 69label1: 70 if (cond()) 71 goto label0; /* expected-error {{cannot jump from this goto statement to its label}} */ 72 if (cond()) 73 goto label2; 74 } 75 76label2: 77 if (cond()) 78 goto label0; /* expected-error {{cannot jump from this goto statement to its label}} */ 79 if (cond()) 80 goto label1; /* expected-error{{cannot jump from this goto statement to its label}} */ 81} 82