Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | /* RUN: %clang_cc1 -Wall -fsyntax-only -verify -std=c89 -pedantic %s |
Chris Lattner | 4d00f2a | 2009-04-22 00:54:41 +0000 | [diff] [blame] | 2 | */ |
Anders Carlsson | 1fe379f | 2008-08-25 18:16:36 +0000 | [diff] [blame] | 3 | |
| 4 | @class NSArray; |
| 5 | |
Chris Lattner | 4d00f2a | 2009-04-22 00:54:41 +0000 | [diff] [blame] | 6 | void 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); |
| 17 | for (id thisKey in keys); |
Chris Lattner | d162584 | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 18 | } |
Fariborz Jahanian | 6147806 | 2011-03-09 20:18:06 +0000 | [diff] [blame] | 19 | |
| 20 | /* // rdar://9072298 */ |
| 21 | @protocol NSObject @end |
| 22 | |
| 23 | @interface NSObject <NSObject> { |
| 24 | Class isa; |
| 25 | } |
| 26 | @end |
| 27 | |
| 28 | typedef 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 | |
| 41 | int main () |
| 42 | { |
| 43 | NSObject<NSFastEnumeration>* collection = ((void*)0); |
| 44 | for (id thing in collection) { } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
John McCall | 29bbd1a | 2012-03-30 05:43:39 +0000 | [diff] [blame] | 49 | /* rdar://problem/11068137 */ |
| 50 | @interface Test2 |
| 51 | @property (assign) id prop; |
| 52 | @end |
| 53 | void test2(NSObject<NSFastEnumeration> *collection) { |
| 54 | Test2 *obj; |
| 55 | for (obj.prop in collection) { /* expected-error {{selector element is not a valid lvalue}} */ |
| 56 | } |
| 57 | } |