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