annotate clang/test/SemaObjCXX/foreach.mm @ 206:f17a3b42b08b

Added tag before-12 for changeset b7591485f4cd
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 07 Jun 2021 21:25:57 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=c++11 %s
anatofuz
parents:
diff changeset
2 // rdar://9293227
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 @class NSArray;
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 void f(NSArray *a) {
anatofuz
parents:
diff changeset
7 id keys;
anatofuz
parents:
diff changeset
8 for (int i : a); // expected-error{{selector element type 'int' is not a valid object}}
anatofuz
parents:
diff changeset
9 for ((id)2 : a); // expected-error {{for range declaration must declare a variable}}
anatofuz
parents:
diff changeset
10 for (2 : a); // expected-error {{for range declaration must declare a variable}}
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 for (id thisKey : keys);
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 for (auto thisKey : keys) { } // expected-warning{{'auto' deduced as 'id' in declaration of 'thisKey'}}
anatofuz
parents:
diff changeset
15 }
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 void for_init_stmt() {
anatofuz
parents:
diff changeset
18 for (id keys; id key : keys) {} // expected-warning{{extension}} expected-error{{not supported}}
anatofuz
parents:
diff changeset
19 }
anatofuz
parents:
diff changeset
20 template<typename T> void for_init_stmt_tmpl() {
anatofuz
parents:
diff changeset
21 for (T keys; id key : keys) {} // expected-warning{{extension}} expected-error{{not supported}}
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23 template void for_init_stmt_tmpl<id>(); // expected-note {{in instantiation of}}
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 template<typename Collection>
anatofuz
parents:
diff changeset
26 void ft(Collection col) {
anatofuz
parents:
diff changeset
27 for (id x : col) { }
anatofuz
parents:
diff changeset
28 for (auto x : col) { }
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 template void ft(NSArray *);
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 /* // rdar://9072298 */
anatofuz
parents:
diff changeset
34 @protocol NSObject @end
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 @interface NSObject <NSObject> {
anatofuz
parents:
diff changeset
37 Class isa;
anatofuz
parents:
diff changeset
38 }
anatofuz
parents:
diff changeset
39 @end
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 typedef struct {
anatofuz
parents:
diff changeset
42 unsigned long state;
anatofuz
parents:
diff changeset
43 id *itemsPtr;
anatofuz
parents:
diff changeset
44 unsigned long *mutationsPtr;
anatofuz
parents:
diff changeset
45 unsigned long extra[5];
anatofuz
parents:
diff changeset
46 } NSFastEnumerationState;
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 @protocol NSFastEnumeration
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 - (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 @end
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 int main ()
anatofuz
parents:
diff changeset
55 {
anatofuz
parents:
diff changeset
56 NSObject<NSFastEnumeration>* collection = 0;
anatofuz
parents:
diff changeset
57 for (id thing : collection) { }
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 id array;
anatofuz
parents:
diff changeset
60 for (int (^b)(void) : array) {
anatofuz
parents:
diff changeset
61 if (b() == 10000) {
anatofuz
parents:
diff changeset
62 return 1;
anatofuz
parents:
diff changeset
63 }
anatofuz
parents:
diff changeset
64 }
anatofuz
parents:
diff changeset
65 return 0;
anatofuz
parents:
diff changeset
66 }
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 /* rdar://problem/11068137 */
anatofuz
parents:
diff changeset
69 @interface Test2
anatofuz
parents:
diff changeset
70 @property (assign) id prop;
anatofuz
parents:
diff changeset
71 @end
anatofuz
parents:
diff changeset
72 void test2(NSObject<NSFastEnumeration> *collection) {
anatofuz
parents:
diff changeset
73 Test2 *obj;
anatofuz
parents:
diff changeset
74 for (obj.prop : collection) { // expected-error {{for range declaration must declare a variable}}
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76 }
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 void testErrors(NSArray *array) {
anatofuz
parents:
diff changeset
79 typedef int fn(int);
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 for (fn x in array) { } // expected-error{{non-variable declaration in 'for' loop}}
anatofuz
parents:
diff changeset
82 }