blob: 5b73be5851f425b657f3bbf214e1dc764400cfb0 [file] [log] [blame]
Anders Carlssone9b801f2011-02-22 01:52:06 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
Steve Naroff1fc51942009-04-14 20:53:38 +00002
3@class A, B, C;
4
Chris Lattnera5251fc2009-04-18 09:36:27 +00005void test1() {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +00006 goto L; // expected-error{{goto into protected scope}}
7 goto L2; // expected-error{{goto into protected scope}}
8 goto L3; // expected-error{{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 {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000020 goto L4; // expected-error{{goto into protected scope}}
21 goto L5; // expected-error{{goto into protected scope}}
Chris Lattner07e775d2009-04-18 21:28:52 +000022 } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
23 L5: ;
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000024 goto L6; // expected-error{{goto into protected scope}}
Chris Lattner07e775d2009-04-18 21:28:52 +000025 } @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) {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000035 goto L7; // expected-error{{goto into protected scope}}
Chris Lattner07e775d2009-04-18 21:28:52 +000036 } @finally {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000037 goto L7; // expected-error{{goto into protected scope}}
Chris Lattner07e775d2009-04-18 21:28:52 +000038 }
39
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000040 goto L8; // expected-error{{goto into protected scope}}
Chris Lattner07e775d2009-04-18 21:28:52 +000041 @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;
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000050 goto L9; // expected-error{{goto into protected scope}}
Chris Lattner46c3c4b2009-04-21 06:01:00 +000051 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 {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000082 goto blargh; // expected-error {{goto into protected scope}}
Chris Lattner5223af82009-04-18 22:37:38 +000083 } @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;
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000090 goto L0; // expected-error {{goto into protected scope}}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000091 typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
92 L0:
93
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000094 goto L1; // expected-error {{goto into protected scope}}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000095 A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
96 L1:
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000097 goto L2; // expected-error {{goto into protected scope}}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000098 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