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