blob: 0835373ba7484c4d1394896c7714c32e0c45521c [file] [log] [blame]
Steve Naroff1fc51942009-04-14 20:53:38 +00001// RUN: clang-cc -fsyntax-only -verify %s
2
3@class A, B, C;
4
Chris Lattnera5251fc2009-04-18 09:36:27 +00005void test1() {
6 goto L; // expected-error{{illegal goto into protected scope}}
7 goto L2; // expected-error{{illegal goto into protected scope}}
8 goto L3; // expected-error{{illegal goto into protected scope}}
Chris Lattner07e775d2009-04-18 21:28:52 +00009 @try { // expected-note {{jump bypasses initialization of @try block}}
Steve Naroff1fc51942009-04-14 20:53:38 +000010L: ;
Chris Lattner07e775d2009-04-18 21:28:52 +000011 } @catch (A *x) { // expected-note {{jump bypasses initialization of @catch block}}
Steve Naroff1fc51942009-04-14 20:53:38 +000012L2: ;
13 } @catch (B *x) {
14 } @catch (C *c) {
Chris Lattner07e775d2009-04-18 21:28:52 +000015 } @finally {// expected-note {{jump bypasses initialization of @finally block}}
Steve Naroff1fc51942009-04-14 20:53:38 +000016L3: ;
17 }
Chris Lattner07e775d2009-04-18 21:28:52 +000018
19 @try {
20 goto L4; // expected-error{{illegal goto into protected scope}}
21 goto L5; // expected-error{{illegal goto into protected scope}}
22 } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
23 L5: ;
24 goto L6; // expected-error{{illegal goto into protected scope}}
25 } @catch (B *c) { // expected-note {{jump bypasses initialization of @catch block}}
26 L6: ;
27 } @finally { // expected-note {{jump bypasses initialization of @finally block}}
28 L4: ;
29 }
30
31
32 @try { // expected-note 2 {{jump bypasses initialization of @try block}}
33 L7: ;
34 } @catch (C *c) {
35 goto L7; // expected-error{{illegal goto into protected scope}}
36 } @finally {
37 goto L7; // expected-error{{illegal goto into protected scope}}
38 }
39
40 goto L8; // expected-error{{illegal goto into protected scope}}
41 @try {
Chris Lattnerdabbad02009-04-18 22:35:34 +000042 } @catch (A *c) {
43 } @catch (B *c) {
Chris Lattner07e775d2009-04-18 21:28:52 +000044 } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
45 L8: ;
46 }
Chris Lattner46c3c4b2009-04-21 06:01:00 +000047
48 // rdar://6810106
49 id X;
50 goto L9; // expected-error{{illegal goto into protected scope}}
51 goto L10; // ok
52 @synchronized // expected-note {{jump bypasses initialization of @synchronized block}}
53 ( ({ L10: ; X; })) {
54 L9:
55 ;
56 }
Steve Naroff1fc51942009-04-14 20:53:38 +000057}
Steve Naroffb25ddfb2009-04-15 14:38:36 +000058
Chris Lattnera5251fc2009-04-18 09:36:27 +000059void test2(int a) {
Steve Naroffb25ddfb2009-04-15 14:38:36 +000060 if (a) goto L0;
61 @try {} @finally {}
62 L0:
63 return;
64}
Chris Lattnera5251fc2009-04-18 09:36:27 +000065
66// rdar://6803963
67void test3() {
68 @try {
69 goto blargh;
70 blargh: ;
71 } @catch (...) {}
72}
Chris Lattner5223af82009-04-18 22:37:38 +000073
74@interface Greeter
75+ (void) hello;
76@end
77
78@implementation Greeter
79+ (void) hello {
80
81 @try {
82 goto blargh; // expected-error {{illegal goto into protected scope}}
83 } @catch (...) { // expected-note {{jump bypasses initialization of @catch block}}
84 blargh: ;
85 }
86}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000087
88+ (void)meth2 {
89 int n; void *P;
90 goto L0; // expected-error {{illegal goto into protected scope}}
91 typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
92 L0:
93
94 goto L1; // expected-error {{illegal goto into protected scope}}
95 A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
96 L1:
97 goto L2; // expected-error {{illegal goto into protected scope}}
98 A d[n]; // expected-note {{jump bypasses initialization of variable length array}}
99 L2:
100 return;
101}
102
Chris Lattner5223af82009-04-18 22:37:38 +0000103@end