Debian Codegraph @

clang/test/SemaObjC/foreach.m

raw
1 /* RUN: %clang_cc1 -Wall -Wno-unused-but-set-variable -fsyntax-only -verify -std=c89 -pedantic %s
2 */
3
4 @class NSArray;
5
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 */
15 for (id thisKey in keys); /* expected-warning {{unused variable 'thisKey'}} */
16 for (id thisKey in keys); /* expected-warning {{unused variable 'thisKey'}} */
17 }
18
19 @protocol NSObject @end
20
21 @interface NSObject <NSObject> {
22 Class isa;
23 }
24 @end
25
26 typedef struct {
27 unsigned long state;
28 id *itemsPtr;
29 unsigned long *mutationsPtr;
30 unsigned long extra[5];
31 } NSFastEnumerationState;
32
33 @protocol NSFastEnumeration
34
35 - (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
36
37 @end
38
39 int main (void)
40 {
41 NSObject<NSFastEnumeration>* collection = ((void*)0);
42 for (id thing in collection) { } /* expected-warning {{unused variable 'thing'}} */
43
44 return 0;
45 }
46
47 @interface Test2
48 @property (assign) id prop;
49 @end
50 void test2(NSObject<NSFastEnumeration> *collection) {
51 Test2 *obj;
52 for (obj.prop in collection) { /* expected-error {{selector element is not a valid lvalue}} */
53 }
54 }
55
56 int cond(void);
57
58 void test3(NSObject<NSFastEnumeration> *a0, NSObject<NSFastEnumeration> *a1) {
59 for (id i in a0) { /* expected-note 2 {{jump enters Objective-C fast enumeration loop}} */
60 for (id j in a1) { /* expected-note 2 {{jump enters Objective-C fast enumeration loop}} */
61 (void)i, (void)j;
62 label0:
63 if (cond())
64 goto label1;
65 }
66 label1:
67 if (cond())
68 goto label0; /* expected-error {{cannot jump from this goto statement to its label}} */
69 if (cond())
70 goto label2;
71 }
72
73 label2:
74 if (cond())
75 goto label0; /* expected-error {{cannot jump from this goto statement to its label}} */
76 if (cond())
77 goto label1; /* expected-error{{cannot jump from this goto statement to its label}} */
78 }