xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/scope-check.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fcxx-exceptions %s -Wno-unreachable-code
2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fcxx-exceptions -std=gnu++11 %s -Wno-unreachable-code
3f4a2713aSLionel Sambuc 
4*0a6a1f1dSLionel Sambuc namespace testInvalid {
5*0a6a1f1dSLionel Sambuc Invalid inv; // expected-error {{unknown type name}}
6*0a6a1f1dSLionel Sambuc // Make sure this doesn't assert.
fn()7*0a6a1f1dSLionel Sambuc void fn()
8*0a6a1f1dSLionel Sambuc {
9*0a6a1f1dSLionel Sambuc     int c = 0;
10*0a6a1f1dSLionel Sambuc     if (inv)
11*0a6a1f1dSLionel Sambuc Here: ;
12*0a6a1f1dSLionel Sambuc     goto Here;
13*0a6a1f1dSLionel Sambuc }
14*0a6a1f1dSLionel Sambuc }
15*0a6a1f1dSLionel Sambuc 
16f4a2713aSLionel Sambuc namespace test0 {
17f4a2713aSLionel Sambuc   struct D { ~D(); };
18f4a2713aSLionel Sambuc 
f(bool b)19f4a2713aSLionel Sambuc   int f(bool b) {
20f4a2713aSLionel Sambuc     if (b) {
21f4a2713aSLionel Sambuc       D d;
22f4a2713aSLionel Sambuc       goto end;
23f4a2713aSLionel Sambuc     }
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc   end:
26f4a2713aSLionel Sambuc     return 1;
27f4a2713aSLionel Sambuc   }
28f4a2713aSLionel Sambuc }
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc namespace test1 {
31f4a2713aSLionel Sambuc   struct C { C(); };
32f4a2713aSLionel Sambuc 
f(bool b)33f4a2713aSLionel Sambuc   int f(bool b) {
34f4a2713aSLionel Sambuc     if (b)
35*0a6a1f1dSLionel Sambuc       goto foo; // expected-error {{cannot jump}}
36f4a2713aSLionel Sambuc     C c; // expected-note {{jump bypasses variable initialization}}
37f4a2713aSLionel Sambuc   foo:
38f4a2713aSLionel Sambuc     return 1;
39f4a2713aSLionel Sambuc   }
40f4a2713aSLionel Sambuc }
41f4a2713aSLionel Sambuc 
42f4a2713aSLionel Sambuc namespace test2 {
43f4a2713aSLionel Sambuc   struct C { C(); };
44f4a2713aSLionel Sambuc 
f(void ** ip)45f4a2713aSLionel Sambuc   int f(void **ip) {
46f4a2713aSLionel Sambuc     static void *ips[] = { &&lbl1, &&lbl2 };
47f4a2713aSLionel Sambuc 
48f4a2713aSLionel Sambuc     C c;
49f4a2713aSLionel Sambuc     goto *ip;
50f4a2713aSLionel Sambuc   lbl1:
51f4a2713aSLionel Sambuc     return 0;
52f4a2713aSLionel Sambuc   lbl2:
53f4a2713aSLionel Sambuc     return 1;
54f4a2713aSLionel Sambuc   }
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc namespace test3 {
58f4a2713aSLionel Sambuc   struct C { C(); };
59f4a2713aSLionel Sambuc 
f(void ** ip)60f4a2713aSLionel Sambuc   int f(void **ip) {
61f4a2713aSLionel Sambuc     static void *ips[] = { &&lbl1, &&lbl2 };
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc     goto *ip;
64f4a2713aSLionel Sambuc   lbl1: {
65f4a2713aSLionel Sambuc     C c;
66f4a2713aSLionel Sambuc     return 0;
67f4a2713aSLionel Sambuc   }
68f4a2713aSLionel Sambuc   lbl2:
69f4a2713aSLionel Sambuc     return 1;
70f4a2713aSLionel Sambuc   }
71f4a2713aSLionel Sambuc }
72f4a2713aSLionel Sambuc 
73f4a2713aSLionel Sambuc namespace test4 {
74f4a2713aSLionel Sambuc   struct C { C(); };
75f4a2713aSLionel Sambuc   struct D { ~D(); };
76f4a2713aSLionel Sambuc 
f(void ** ip)77f4a2713aSLionel Sambuc   int f(void **ip) {
78f4a2713aSLionel Sambuc     static void *ips[] = { &&lbl1, &&lbl2 };
79f4a2713aSLionel Sambuc 
80f4a2713aSLionel Sambuc     C c0;
81f4a2713aSLionel Sambuc 
82*0a6a1f1dSLionel Sambuc     goto *ip; // expected-error {{cannot jump}}
83f4a2713aSLionel Sambuc     C c1; // expected-note {{jump bypasses variable initialization}}
84f4a2713aSLionel Sambuc   lbl1: // expected-note {{possible target of indirect goto}}
85f4a2713aSLionel Sambuc     return 0;
86f4a2713aSLionel Sambuc   lbl2:
87f4a2713aSLionel Sambuc     return 1;
88f4a2713aSLionel Sambuc   }
89f4a2713aSLionel Sambuc }
90f4a2713aSLionel Sambuc 
91f4a2713aSLionel Sambuc namespace test5 {
92f4a2713aSLionel Sambuc   struct C { C(); };
93f4a2713aSLionel Sambuc   struct D { ~D(); };
94f4a2713aSLionel Sambuc 
f(void ** ip)95f4a2713aSLionel Sambuc   int f(void **ip) {
96f4a2713aSLionel Sambuc     static void *ips[] = { &&lbl1, &&lbl2 };
97f4a2713aSLionel Sambuc     C c0;
98f4a2713aSLionel Sambuc 
99f4a2713aSLionel Sambuc     goto *ip;
100f4a2713aSLionel Sambuc   lbl1: // expected-note {{possible target of indirect goto}}
101f4a2713aSLionel Sambuc     return 0;
102f4a2713aSLionel Sambuc   lbl2:
103f4a2713aSLionel Sambuc     if (ip[1]) {
104f4a2713aSLionel Sambuc       D d; // expected-note {{jump exits scope of variable with non-trivial destructor}}
105f4a2713aSLionel Sambuc       ip += 2;
106*0a6a1f1dSLionel Sambuc       goto *ip; // expected-error {{cannot jump}}
107f4a2713aSLionel Sambuc     }
108f4a2713aSLionel Sambuc     return 1;
109f4a2713aSLionel Sambuc   }
110f4a2713aSLionel Sambuc }
111f4a2713aSLionel Sambuc 
112f4a2713aSLionel Sambuc namespace test6 {
113f4a2713aSLionel Sambuc   struct C { C(); };
114f4a2713aSLionel Sambuc 
f(unsigned s0,unsigned s1,void ** ip)115f4a2713aSLionel Sambuc   unsigned f(unsigned s0, unsigned s1, void **ip) {
116f4a2713aSLionel Sambuc     static void *ips[] = { &&lbl1, &&lbl2, &&lbl3, &&lbl4 };
117f4a2713aSLionel Sambuc     C c0;
118f4a2713aSLionel Sambuc 
119f4a2713aSLionel Sambuc     goto *ip;
120f4a2713aSLionel Sambuc   lbl1:
121f4a2713aSLionel Sambuc     s0++;
122f4a2713aSLionel Sambuc     goto *++ip;
123f4a2713aSLionel Sambuc   lbl2:
124f4a2713aSLionel Sambuc     s0 -= s1;
125f4a2713aSLionel Sambuc     goto *++ip;
126f4a2713aSLionel Sambuc   lbl3: {
127f4a2713aSLionel Sambuc     unsigned tmp = s0;
128f4a2713aSLionel Sambuc     s0 = s1;
129f4a2713aSLionel Sambuc     s1 = tmp;
130f4a2713aSLionel Sambuc     goto *++ip;
131f4a2713aSLionel Sambuc   }
132f4a2713aSLionel Sambuc   lbl4:
133f4a2713aSLionel Sambuc     return s0;
134f4a2713aSLionel Sambuc   }
135f4a2713aSLionel Sambuc }
136f4a2713aSLionel Sambuc 
137f4a2713aSLionel Sambuc // C++0x says it's okay to skip non-trivial initializers on static
138f4a2713aSLionel Sambuc // locals, and we implement that in '03 as well.
139f4a2713aSLionel Sambuc namespace test7 {
140f4a2713aSLionel Sambuc   struct C { C(); };
141f4a2713aSLionel Sambuc 
test()142f4a2713aSLionel Sambuc   void test() {
143f4a2713aSLionel Sambuc     goto foo;
144f4a2713aSLionel Sambuc     static C c;
145f4a2713aSLionel Sambuc   foo:
146f4a2713aSLionel Sambuc     return;
147f4a2713aSLionel Sambuc   }
148f4a2713aSLionel Sambuc }
149f4a2713aSLionel Sambuc 
150f4a2713aSLionel Sambuc // PR7789
151f4a2713aSLionel Sambuc namespace test8 {
test1(int c)152f4a2713aSLionel Sambuc   void test1(int c) {
153f4a2713aSLionel Sambuc     switch (c) {
154f4a2713aSLionel Sambuc     case 0:
155f4a2713aSLionel Sambuc       int x = 56; // expected-note {{jump bypasses variable initialization}}
156*0a6a1f1dSLionel Sambuc     case 1:       // expected-error {{cannot jump}}
157f4a2713aSLionel Sambuc       x = 10;
158f4a2713aSLionel Sambuc     }
159f4a2713aSLionel Sambuc   }
160f4a2713aSLionel Sambuc 
test2()161f4a2713aSLionel Sambuc   void test2() {
162*0a6a1f1dSLionel Sambuc     goto l2;     // expected-error {{cannot jump}}
163f4a2713aSLionel Sambuc   l1: int x = 5; // expected-note {{jump bypasses variable initialization}}
164f4a2713aSLionel Sambuc   l2: x++;
165f4a2713aSLionel Sambuc   }
166f4a2713aSLionel Sambuc }
167f4a2713aSLionel Sambuc 
168f4a2713aSLionel Sambuc namespace test9 {
169f4a2713aSLionel Sambuc   struct S { int i; };
test1()170f4a2713aSLionel Sambuc   void test1() {
171f4a2713aSLionel Sambuc     goto foo;
172f4a2713aSLionel Sambuc     S s;
173f4a2713aSLionel Sambuc   foo:
174f4a2713aSLionel Sambuc     return;
175f4a2713aSLionel Sambuc   }
test2(unsigned x,unsigned y)176f4a2713aSLionel Sambuc   unsigned test2(unsigned x, unsigned y) {
177f4a2713aSLionel Sambuc     switch (x) {
178f4a2713aSLionel Sambuc     case 2:
179f4a2713aSLionel Sambuc       S s;
180f4a2713aSLionel Sambuc       if (y > 42) return x + y;
181f4a2713aSLionel Sambuc     default:
182f4a2713aSLionel Sambuc       return x - 2;
183f4a2713aSLionel Sambuc     }
184f4a2713aSLionel Sambuc   }
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc 
187f4a2713aSLionel Sambuc // http://llvm.org/PR10462
188f4a2713aSLionel Sambuc namespace PR10462 {
189f4a2713aSLionel Sambuc   enum MyEnum {
190f4a2713aSLionel Sambuc     something_valid,
191f4a2713aSLionel Sambuc     something_invalid
192f4a2713aSLionel Sambuc   };
193f4a2713aSLionel Sambuc 
recurse()194f4a2713aSLionel Sambuc   bool recurse() {
195f4a2713aSLionel Sambuc     MyEnum K;
196f4a2713aSLionel Sambuc     switch (K) { // expected-warning {{enumeration value 'something_invalid' not handled in switch}}
197f4a2713aSLionel Sambuc     case something_valid:
198f4a2713aSLionel Sambuc     case what_am_i_thinking: // expected-error {{use of undeclared identifier}}
199f4a2713aSLionel Sambuc       int *X = 0;
200f4a2713aSLionel Sambuc       if (recurse()) {
201f4a2713aSLionel Sambuc       }
202f4a2713aSLionel Sambuc 
203f4a2713aSLionel Sambuc       break;
204f4a2713aSLionel Sambuc     }
205f4a2713aSLionel Sambuc   }
206f4a2713aSLionel Sambuc }
207f4a2713aSLionel Sambuc 
208f4a2713aSLionel Sambuc namespace test10 {
test()209f4a2713aSLionel Sambuc   int test() {
210f4a2713aSLionel Sambuc     static void *ps[] = { &&a0 };
211*0a6a1f1dSLionel Sambuc     goto *&&a0; // expected-error {{cannot jump}}
212f4a2713aSLionel Sambuc     int a = 3; // expected-note {{jump bypasses variable initialization}}
213f4a2713aSLionel Sambuc   a0:
214f4a2713aSLionel Sambuc     return 0;
215f4a2713aSLionel Sambuc   }
216f4a2713aSLionel Sambuc }
217f4a2713aSLionel Sambuc 
218f4a2713aSLionel Sambuc // pr13812
219f4a2713aSLionel Sambuc namespace test11 {
220f4a2713aSLionel Sambuc   struct C {
221f4a2713aSLionel Sambuc     C(int x);
222f4a2713aSLionel Sambuc     ~C();
223f4a2713aSLionel Sambuc   };
f(void ** ip)224f4a2713aSLionel Sambuc   void f(void **ip) {
225f4a2713aSLionel Sambuc     static void *ips[] = { &&l0 };
226f4a2713aSLionel Sambuc   l0:  // expected-note {{possible target of indirect goto}}
227f4a2713aSLionel Sambuc     C c0 = 42; // expected-note {{jump exits scope of variable with non-trivial destructor}}
228*0a6a1f1dSLionel Sambuc     goto *ip; // expected-error {{cannot jump}}
229f4a2713aSLionel Sambuc   }
230f4a2713aSLionel Sambuc }
231f4a2713aSLionel Sambuc 
232f4a2713aSLionel Sambuc namespace test12 {
233f4a2713aSLionel Sambuc   struct C {
234f4a2713aSLionel Sambuc     C(int x);
235f4a2713aSLionel Sambuc     ~C();
236f4a2713aSLionel Sambuc   };
f(void ** ip)237f4a2713aSLionel Sambuc   void f(void **ip) {
238f4a2713aSLionel Sambuc     static void *ips[] = { &&l0 };
239f4a2713aSLionel Sambuc     const C c0 = 17;
240f4a2713aSLionel Sambuc   l0: // expected-note {{possible target of indirect goto}}
241*0a6a1f1dSLionel Sambuc     const C &c1 = 42; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
242f4a2713aSLionel Sambuc     const C &c2 = c0;
243*0a6a1f1dSLionel Sambuc     goto *ip; // expected-error {{cannot jump}}
244f4a2713aSLionel Sambuc   }
245f4a2713aSLionel Sambuc }
246f4a2713aSLionel Sambuc 
247f4a2713aSLionel Sambuc namespace test13 {
248f4a2713aSLionel Sambuc   struct C {
249f4a2713aSLionel Sambuc     C(int x);
250f4a2713aSLionel Sambuc     ~C();
251f4a2713aSLionel Sambuc     int i;
252f4a2713aSLionel Sambuc   };
f(void ** ip)253f4a2713aSLionel Sambuc   void f(void **ip) {
254f4a2713aSLionel Sambuc     static void *ips[] = { &&l0 };
255f4a2713aSLionel Sambuc   l0: // expected-note {{possible target of indirect goto}}
256*0a6a1f1dSLionel Sambuc     const int &c1 = C(1).i; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
257*0a6a1f1dSLionel Sambuc     goto *ip;  // expected-error {{cannot jump}}
258f4a2713aSLionel Sambuc   }
259f4a2713aSLionel Sambuc }
260f4a2713aSLionel Sambuc 
261f4a2713aSLionel Sambuc namespace test14 {
262f4a2713aSLionel Sambuc   struct C {
263f4a2713aSLionel Sambuc     C(int x);
264f4a2713aSLionel Sambuc     ~C();
265f4a2713aSLionel Sambuc     operator int&() const;
266f4a2713aSLionel Sambuc   };
f(void ** ip)267f4a2713aSLionel Sambuc   void f(void **ip) {
268f4a2713aSLionel Sambuc     static void *ips[] = { &&l0 };
269f4a2713aSLionel Sambuc   l0:
270f4a2713aSLionel Sambuc     // no warning since the C temporary is destructed before the goto.
271f4a2713aSLionel Sambuc     const int &c1 = C(1);
272f4a2713aSLionel Sambuc     goto *ip;
273f4a2713aSLionel Sambuc   }
274f4a2713aSLionel Sambuc }
275f4a2713aSLionel Sambuc 
276f4a2713aSLionel Sambuc // PR14225
277f4a2713aSLionel Sambuc namespace test15 {
f1()278f4a2713aSLionel Sambuc   void f1() try {
279*0a6a1f1dSLionel Sambuc     goto x; // expected-error {{cannot jump}}
280f4a2713aSLionel Sambuc   } catch(...) {  // expected-note {{jump bypasses initialization of catch block}}
281f4a2713aSLionel Sambuc     x: ;
282f4a2713aSLionel Sambuc   }
f2()283f4a2713aSLionel Sambuc   void f2() try {  // expected-note {{jump bypasses initialization of try block}}
284f4a2713aSLionel Sambuc     x: ;
285f4a2713aSLionel Sambuc   } catch(...) {
286*0a6a1f1dSLionel Sambuc     goto x; // expected-error {{cannot jump}}
287f4a2713aSLionel Sambuc   }
288f4a2713aSLionel Sambuc }
289f4a2713aSLionel Sambuc 
290f4a2713aSLionel Sambuc namespace test16 {
291f4a2713aSLionel Sambuc   struct S { int n; };
f()292f4a2713aSLionel Sambuc   int f() {
293*0a6a1f1dSLionel Sambuc     goto x; // expected-error {{cannot jump}}
294f4a2713aSLionel Sambuc     const S &s = S(); // expected-note {{jump bypasses variable initialization}}
295f4a2713aSLionel Sambuc x:  return s.n;
296f4a2713aSLionel Sambuc   }
297f4a2713aSLionel Sambuc }
298f4a2713aSLionel Sambuc 
299f4a2713aSLionel Sambuc #if __cplusplus >= 201103L
300f4a2713aSLionel Sambuc namespace test17 {
301f4a2713aSLionel Sambuc   struct S { int get(); private: int n; };
f()302f4a2713aSLionel Sambuc   int f() {
303*0a6a1f1dSLionel Sambuc     goto x; // expected-error {{cannot jump}}
304f4a2713aSLionel Sambuc     S s = {}; // expected-note {{jump bypasses variable initialization}}
305f4a2713aSLionel Sambuc x:  return s.get();
306f4a2713aSLionel Sambuc   }
307f4a2713aSLionel Sambuc }
308f4a2713aSLionel Sambuc #endif
309f4a2713aSLionel Sambuc 
310*0a6a1f1dSLionel Sambuc namespace test18 {
311*0a6a1f1dSLionel Sambuc   struct A { ~A(); };
312*0a6a1f1dSLionel Sambuc   struct B { const int &r; const A &a; };
f()313*0a6a1f1dSLionel Sambuc   int f() {
314*0a6a1f1dSLionel Sambuc     void *p = &&x;
315*0a6a1f1dSLionel Sambuc     const A a = A();
316*0a6a1f1dSLionel Sambuc   x:
317*0a6a1f1dSLionel Sambuc     B b = { 0, a }; // ok
318*0a6a1f1dSLionel Sambuc     goto *p;
319*0a6a1f1dSLionel Sambuc   }
g()320*0a6a1f1dSLionel Sambuc   int g() {
321*0a6a1f1dSLionel Sambuc     void *p = &&x;
322*0a6a1f1dSLionel Sambuc   x: // expected-note {{possible target of indirect goto}}
323*0a6a1f1dSLionel Sambuc     B b = { 0, A() }; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
324*0a6a1f1dSLionel Sambuc     goto *p; // expected-error {{cannot jump}}
325*0a6a1f1dSLionel Sambuc   }
326*0a6a1f1dSLionel Sambuc }
327*0a6a1f1dSLionel Sambuc 
328*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
329*0a6a1f1dSLionel Sambuc namespace std {
330*0a6a1f1dSLionel Sambuc   typedef decltype(sizeof(int)) size_t;
331*0a6a1f1dSLionel Sambuc   template<typename T> struct initializer_list {
332*0a6a1f1dSLionel Sambuc     const T *begin;
333*0a6a1f1dSLionel Sambuc     size_t size;
334*0a6a1f1dSLionel Sambuc     initializer_list(const T *, size_t);
335*0a6a1f1dSLionel Sambuc   };
336*0a6a1f1dSLionel Sambuc }
337*0a6a1f1dSLionel Sambuc namespace test19 {
338*0a6a1f1dSLionel Sambuc   struct A { ~A(); };
339*0a6a1f1dSLionel Sambuc 
f()340*0a6a1f1dSLionel Sambuc   int f() {
341*0a6a1f1dSLionel Sambuc     void *p = &&x;
342*0a6a1f1dSLionel Sambuc     A a;
343*0a6a1f1dSLionel Sambuc   x: // expected-note {{possible target of indirect goto}}
344*0a6a1f1dSLionel Sambuc     std::initializer_list<A> il = { a }; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
345*0a6a1f1dSLionel Sambuc     goto *p; // expected-error {{cannot jump}}
346*0a6a1f1dSLionel Sambuc   }
347*0a6a1f1dSLionel Sambuc }
348*0a6a1f1dSLionel Sambuc 
349*0a6a1f1dSLionel Sambuc namespace test20 {
350*0a6a1f1dSLionel Sambuc   struct A { ~A(); };
351*0a6a1f1dSLionel Sambuc   struct B {
352*0a6a1f1dSLionel Sambuc     const A &a;
353*0a6a1f1dSLionel Sambuc   };
354*0a6a1f1dSLionel Sambuc 
f()355*0a6a1f1dSLionel Sambuc   int f() {
356*0a6a1f1dSLionel Sambuc     void *p = &&x;
357*0a6a1f1dSLionel Sambuc     A a;
358*0a6a1f1dSLionel Sambuc   x:
359*0a6a1f1dSLionel Sambuc     std::initializer_list<B> il = {
360*0a6a1f1dSLionel Sambuc       a,
361*0a6a1f1dSLionel Sambuc       a
362*0a6a1f1dSLionel Sambuc     };
363*0a6a1f1dSLionel Sambuc     goto *p;
364*0a6a1f1dSLionel Sambuc   }
g()365*0a6a1f1dSLionel Sambuc   int g() {
366*0a6a1f1dSLionel Sambuc     void *p = &&x;
367*0a6a1f1dSLionel Sambuc     A a;
368*0a6a1f1dSLionel Sambuc   x: // expected-note {{possible target of indirect goto}}
369*0a6a1f1dSLionel Sambuc     std::initializer_list<B> il = {
370*0a6a1f1dSLionel Sambuc       a,
371*0a6a1f1dSLionel Sambuc       { A() } // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
372*0a6a1f1dSLionel Sambuc     };
373*0a6a1f1dSLionel Sambuc     goto *p; // expected-error {{cannot jump}}
374*0a6a1f1dSLionel Sambuc   }
375*0a6a1f1dSLionel Sambuc }
376*0a6a1f1dSLionel Sambuc #endif
377*0a6a1f1dSLionel Sambuc 
378*0a6a1f1dSLionel Sambuc namespace test21 {
f()379*0a6a1f1dSLionel Sambuc   template<typename T> void f() {
380*0a6a1f1dSLionel Sambuc   goto x; // expected-error {{cannot jump}}
381*0a6a1f1dSLionel Sambuc     T t; // expected-note {{bypasses}}
382*0a6a1f1dSLionel Sambuc  x: return;
383*0a6a1f1dSLionel Sambuc   }
384*0a6a1f1dSLionel Sambuc 
385*0a6a1f1dSLionel Sambuc   template void f<int>();
386*0a6a1f1dSLionel Sambuc   struct X { ~X(); };
387*0a6a1f1dSLionel Sambuc   template void f<X>(); // expected-note {{instantiation of}}
388*0a6a1f1dSLionel Sambuc }
389*0a6a1f1dSLionel Sambuc 
390*0a6a1f1dSLionel Sambuc namespace PR18217 {
391*0a6a1f1dSLionel Sambuc   typedef int *X;
392*0a6a1f1dSLionel Sambuc 
393*0a6a1f1dSLionel Sambuc   template <typename T>
394*0a6a1f1dSLionel Sambuc   class MyCl {
395*0a6a1f1dSLionel Sambuc     T mem;
396*0a6a1f1dSLionel Sambuc   };
397*0a6a1f1dSLionel Sambuc 
398*0a6a1f1dSLionel Sambuc   class Source {
399*0a6a1f1dSLionel Sambuc     MyCl<X> m;
400*0a6a1f1dSLionel Sambuc   public:
401*0a6a1f1dSLionel Sambuc     int getKind() const;
402*0a6a1f1dSLionel Sambuc   };
403*0a6a1f1dSLionel Sambuc 
404*0a6a1f1dSLionel Sambuc   bool b;
405*0a6a1f1dSLionel Sambuc   template<typename TT>
foo(const Source & SF,MyCl<TT * > Source::* m)406*0a6a1f1dSLionel Sambuc   static void foo(const Source &SF, MyCl<TT *> Source::*m) {
407*0a6a1f1dSLionel Sambuc     switch (SF.getKind()) {
408*0a6a1f1dSLionel Sambuc       case 1: return;
409*0a6a1f1dSLionel Sambuc       case 2: break;
410*0a6a1f1dSLionel Sambuc       case 3:
411*0a6a1f1dSLionel Sambuc       case 4: return;
412*0a6a1f1dSLionel Sambuc     };
413*0a6a1f1dSLionel Sambuc     if (b) {
414*0a6a1f1dSLionel Sambuc       auto &y = const_cast<MyCl<TT *> &>(SF.*m); // expected-warning 0-1{{extension}}
415*0a6a1f1dSLionel Sambuc     }
416*0a6a1f1dSLionel Sambuc   }
417*0a6a1f1dSLionel Sambuc 
getKind() const418*0a6a1f1dSLionel Sambuc   int Source::getKind() const {
419*0a6a1f1dSLionel Sambuc     foo(*this, &Source::m);
420*0a6a1f1dSLionel Sambuc     return 0;
421*0a6a1f1dSLionel Sambuc   }
422*0a6a1f1dSLionel Sambuc }
423*0a6a1f1dSLionel Sambuc 
424*0a6a1f1dSLionel Sambuc namespace test_recovery {
425*0a6a1f1dSLionel Sambuc   // Test that jump scope checking recovers when there are unspecified errors
426*0a6a1f1dSLionel Sambuc   // in the function declaration or body.
427*0a6a1f1dSLionel Sambuc 
test(nexist,int c)428*0a6a1f1dSLionel Sambuc   void test(nexist, int c) { // expected-error {{}}
429*0a6a1f1dSLionel Sambuc     nexist_fn(); // expected-error {{}}
430*0a6a1f1dSLionel Sambuc     goto nexist_label; // expected-error {{use of undeclared label}}
431*0a6a1f1dSLionel Sambuc     goto a0; // expected-error {{cannot jump}}
432*0a6a1f1dSLionel Sambuc     int a = 0; // expected-note {{jump bypasses variable initialization}}
433*0a6a1f1dSLionel Sambuc     a0:;
434*0a6a1f1dSLionel Sambuc 
435*0a6a1f1dSLionel Sambuc     switch (c) {
436*0a6a1f1dSLionel Sambuc     case $: // expected-error {{}}
437*0a6a1f1dSLionel Sambuc     case 0:
438*0a6a1f1dSLionel Sambuc       int x = 56; // expected-note {{jump bypasses variable initialization}}
439*0a6a1f1dSLionel Sambuc     case 1: // expected-error {{cannot jump}}
440*0a6a1f1dSLionel Sambuc       x = 10;
441*0a6a1f1dSLionel Sambuc     }
442f4a2713aSLionel Sambuc   }
443f4a2713aSLionel Sambuc }
444