xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/goto.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -Wall -fblocks %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // PR9463
4*f4a2713aSLionel Sambuc double *end;
5*f4a2713aSLionel Sambuc void f(bool b1, bool b2) {
6*f4a2713aSLionel Sambuc   {
7*f4a2713aSLionel Sambuc     do {
8*f4a2713aSLionel Sambuc       int end = 0;
9*f4a2713aSLionel Sambuc       if (b2) {
10*f4a2713aSLionel Sambuc         do {
11*f4a2713aSLionel Sambuc           goto end;
12*f4a2713aSLionel Sambuc         } while (b2);
13*f4a2713aSLionel Sambuc       }
14*f4a2713aSLionel Sambuc       end = 1;
15*f4a2713aSLionel Sambuc     } while (b1);
16*f4a2713aSLionel Sambuc   }
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc  end:
19*f4a2713aSLionel Sambuc   return;
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc namespace N {
23*f4a2713aSLionel Sambuc   float* end;
24*f4a2713aSLionel Sambuc   void f(bool b1, bool b2) {
25*f4a2713aSLionel Sambuc     {
26*f4a2713aSLionel Sambuc       do {
27*f4a2713aSLionel Sambuc         int end = 0;
28*f4a2713aSLionel Sambuc         if (b2) {
29*f4a2713aSLionel Sambuc           do {
30*f4a2713aSLionel Sambuc             goto end;
31*f4a2713aSLionel Sambuc           } while (b2);
32*f4a2713aSLionel Sambuc         }
33*f4a2713aSLionel Sambuc         end = 1;
34*f4a2713aSLionel Sambuc       } while (b1);
35*f4a2713aSLionel Sambuc     }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc   end:
38*f4a2713aSLionel Sambuc     return;
39*f4a2713aSLionel Sambuc   }
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc void g() {
43*f4a2713aSLionel Sambuc   end = 1; // expected-error{{assigning to 'double *' from incompatible type 'int'}}
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc void h(int end) {
47*f4a2713aSLionel Sambuc   {
48*f4a2713aSLionel Sambuc     goto end; // expected-error{{use of undeclared label 'end'}}
49*f4a2713aSLionel Sambuc   }
50*f4a2713aSLionel Sambuc }
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc void h2(int end) {
53*f4a2713aSLionel Sambuc   {
54*f4a2713aSLionel Sambuc     __label__ end;
55*f4a2713aSLionel Sambuc     goto end;
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc   end:
58*f4a2713aSLionel Sambuc     ::end = 0;
59*f4a2713aSLionel Sambuc   }
60*f4a2713aSLionel Sambuc  end: // expected-warning{{unused label 'end'}}
61*f4a2713aSLionel Sambuc   end = 1;
62*f4a2713aSLionel Sambuc }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc class X {
65*f4a2713aSLionel Sambuc public:
66*f4a2713aSLionel Sambuc   X();
67*f4a2713aSLionel Sambuc };
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc void rdar9135994()
70*f4a2713aSLionel Sambuc {
71*f4a2713aSLionel Sambuc X:
72*f4a2713aSLionel Sambuc     goto X;
73*f4a2713aSLionel Sambuc }
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc namespace PR9495 {
76*f4a2713aSLionel Sambuc   struct NonPOD { NonPOD(); ~NonPOD(); };
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc   void f(bool b) {
79*f4a2713aSLionel Sambuc     NonPOD np;
80*f4a2713aSLionel Sambuc     if (b) {
81*f4a2713aSLionel Sambuc       goto undeclared; // expected-error{{use of undeclared label 'undeclared'}}
82*f4a2713aSLionel Sambuc     }
83*f4a2713aSLionel Sambuc   }
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc   void g() {
86*f4a2713aSLionel Sambuc     (void)^(bool b){
87*f4a2713aSLionel Sambuc       NonPOD np;
88*f4a2713aSLionel Sambuc       if (b) {
89*f4a2713aSLionel Sambuc         goto undeclared; // expected-error{{use of undeclared label 'undeclared'}}
90*f4a2713aSLionel Sambuc       }
91*f4a2713aSLionel Sambuc     };
92*f4a2713aSLionel Sambuc   }
93*f4a2713aSLionel Sambuc }
94*f4a2713aSLionel Sambuc 
95*f4a2713aSLionel Sambuc extern "C" {
96*f4a2713aSLionel Sambuc   void exit(int);
97*f4a2713aSLionel Sambuc }
98*f4a2713aSLionel Sambuc 
99*f4a2713aSLionel Sambuc void f() {
100*f4a2713aSLionel Sambuc   {
101*f4a2713aSLionel Sambuc     goto exit;
102*f4a2713aSLionel Sambuc   }
103*f4a2713aSLionel Sambuc  exit:
104*f4a2713aSLionel Sambuc   return;
105*f4a2713aSLionel Sambuc }
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc namespace PR10620 {
108*f4a2713aSLionel Sambuc   struct S {
109*f4a2713aSLionel Sambuc     ~S() {}
110*f4a2713aSLionel Sambuc   };
111*f4a2713aSLionel Sambuc   void g(const S& s) {
112*f4a2713aSLionel Sambuc     goto done; // expected-error {{goto into protected scope}}
113*f4a2713aSLionel Sambuc     const S s2(s); // expected-note {{jump bypasses variable initialization}}
114*f4a2713aSLionel Sambuc   done:
115*f4a2713aSLionel Sambuc     ;
116*f4a2713aSLionel Sambuc   }
117*f4a2713aSLionel Sambuc }
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc namespace test12 {
120*f4a2713aSLionel Sambuc   struct A { A(); A(const A&); ~A(); };
121*f4a2713aSLionel Sambuc   void test(A a) { // expected-note {{jump enters lifetime of block}} FIXME: wierd location
122*f4a2713aSLionel Sambuc     goto lbl; // expected-error {{goto into protected scope}}
123*f4a2713aSLionel Sambuc     (void) ^{ (void) a; };
124*f4a2713aSLionel Sambuc   lbl:
125*f4a2713aSLionel Sambuc     return;
126*f4a2713aSLionel Sambuc   }
127*f4a2713aSLionel Sambuc }
128