• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    for (2 : a); // expected-error {{for range declaration must declare a variable}}
11
12  for (id thisKey : keys);
13
14  for (auto thisKey : keys) { } // expected-warning{{'auto' deduced as 'id' in declaration of 'thisKey'}}
15}
16
17template<typename Collection>
18void ft(Collection col) {
19  for (id x : col) { }
20  for (auto x : col) { }
21}
22
23template void ft(NSArray *);
24
25/* // rdar://9072298 */
26@protocol NSObject @end
27
28@interface NSObject <NSObject> {
29    Class isa;
30}
31@end
32
33typedef struct {
34    unsigned long state;
35    id *itemsPtr;
36    unsigned long *mutationsPtr;
37    unsigned long extra[5];
38} NSFastEnumerationState;
39
40@protocol NSFastEnumeration
41
42- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
43
44@end
45
46int main ()
47{
48 NSObject<NSFastEnumeration>* collection = 0;
49 for (id thing : collection) { }
50
51 id array;
52 for (int (^b)(void) : array) {
53    if (b() == 10000) {
54        return 1;
55    }
56 }
57 return 0;
58}
59
60/* rdar://problem/11068137 */
61@interface Test2
62@property (assign) id prop;
63@end
64void test2(NSObject<NSFastEnumeration> *collection) {
65  Test2 *obj;
66  for (obj.prop : collection) { // expected-error {{for range declaration must declare a variable}}
67  }
68}
69
70void testErrors(NSArray *array) {
71  typedef int fn(int);
72
73  for (fn x in array) { } // expected-error{{non-variable declaration in 'for' loop}}
74}
75