1// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=c++11 %s
2// rdar://9293227
3
4@class NSArray;
5
6void f(NSArray *a) {
7    id keys;
8    for (int i : a); // expected-error{{selector element type 'int' is not a valid object}}
9    for ((id)2 : a);  // expected-error {{for range declaration must declare a variable}} \
10                      // expected-warning {{expression result unused}}
11    for (2 : a); // expected-error {{for range declaration must declare a variable}} \
12                 // expected-warning {{expression result unused}}
13
14  for (id thisKey : keys);
15
16  for (auto thisKey : keys) { } // expected-warning{{'auto' deduced as 'id' in declaration of 'thisKey'}}
17}
18
19template<typename Collection>
20void ft(Collection col) {
21  for (id x : col) { }
22  for (auto x : col) { }
23}
24
25template void ft(NSArray *);
26
27/* // rdar://9072298 */
28@protocol NSObject @end
29
30@interface NSObject <NSObject> {
31    Class isa;
32}
33@end
34
35typedef struct {
36    unsigned long state;
37    id *itemsPtr;
38    unsigned long *mutationsPtr;
39    unsigned long extra[5];
40} NSFastEnumerationState;
41
42@protocol NSFastEnumeration
43
44- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
45
46@end
47
48int main ()
49{
50 NSObject<NSFastEnumeration>* collection = 0;
51 for (id thing : collection) { }
52
53 id array;
54 for (int (^b)(void) : array) {
55    if (b() == 10000) {
56        return 1;
57    }
58 }
59 return 0;
60}
61
62/* rdar://problem/11068137 */
63@interface Test2
64@property (assign) id prop;
65@end
66void test2(NSObject<NSFastEnumeration> *collection) {
67  Test2 *obj;
68  for (obj.prop : collection) { // expected-error {{for range declaration must declare a variable}} \
69                                // expected-warning {{property access result unused - getters should not be used for side effects}}
70  }
71}
72
73void testErrors(NSArray *array) {
74  typedef int fn(int);
75
76  for (fn x in array) { } // expected-error{{non-variable declaration in 'for' loop}}
77}
78