1 // RUN: %clang_cc1 -triple x86_64-windows -fsyntax-only -verify -fblocks -fcxx-exceptions -fms-extensions %s -Wno-unreachable-code
2 // RUN: %clang_cc1 -triple x86_64-windows -fsyntax-only -verify -fblocks -fcxx-exceptions -fms-extensions -std=gnu++11 %s -Wno-unreachable-code
4 namespace testInvalid {
5 Invalid inv; // expected-error {{unknown type name}}
6 // Make sure this doesn't assert.
35 goto foo; // expected-error {{cannot jump}}
36 C c; // expected-note {{jump bypasses variable initialization}}
46 static void *ips[] = { &&lbl1, &&lbl2 };
61 static void *ips[] = { &&lbl1, &&lbl2 };
78 static void *ips[] = { &&lbl1, &&lbl2 };
82 goto *ip; // expected-error {{cannot jump}}
83 C c1; // expected-note {{jump bypasses variable initialization}}
84 lbl1: // expected-note {{possible target of indirect goto}}
96 static void *ips[] = { &&lbl1, &&lbl2 };
100 lbl1: // expected-note {{possible target of indirect goto}}
104 D d; // expected-note {{jump exits scope of variable with non-trivial destructor}}
106 goto *ip; // expected-error {{cannot jump}}
115 unsigned f(unsigned s0, unsigned s1, void **ip) {
116 static void *ips[] = { &&lbl1, &&lbl2, &&lbl3, &&lbl4 };
137 // C++0x says it's okay to skip non-trivial initializers on static
138 // locals, and we implement that in '03 as well.
155 int x = 56; // expected-note {{jump bypasses variable initialization}}
156 case 1: // expected-error {{cannot jump}}
162 goto l2; // expected-error {{cannot jump}}
163 l1: int x = 5; // expected-note {{jump bypasses variable initialization}}
176 unsigned test2(unsigned x, unsigned y) {
180 if (y > 42) return x + y;
187 // http://llvm.org/PR10462
196 switch (K) { // expected-warning {{enumeration value 'something_invalid' not handled in switch}}
197 case something_valid:
198 case what_am_i_thinking: // expected-error {{use of undeclared identifier}}
210 static void *ps[] = { &&a0 };
211 goto *&&a0; // expected-error {{cannot jump}}
212 int a = 3; // expected-note {{jump bypasses variable initialization}}
225 static void *ips[] = { &&l0 };
226 l0: // expected-note {{possible target of indirect goto}}
227 C c0 = 42; // expected-note {{jump exits scope of variable with non-trivial destructor}}
228 goto *ip; // expected-error {{cannot jump}}
238 static void *ips[] = { &&l0 };
240 l0: // expected-note {{possible target of indirect goto}}
241 const C &c1 = 42; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
243 goto *ip; // expected-error {{cannot jump}}
254 static void *ips[] = { &&l0 };
255 l0: // expected-note {{possible target of indirect goto}}
256 const int &c1 = C(1).i; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
257 goto *ip; // expected-error {{cannot jump}}
265 operator int&() const;
268 static void *ips[] = { &&l0 };
270 // no warning since the C temporary is destructed before the goto.
271 const int &c1 = C(1);
279 goto x; // expected-error {{cannot jump}}
280 } catch(...) { // expected-note {{jump bypasses initialization of catch block}}
283 void f2() try { // expected-note {{jump bypasses initialization of try block}}
286 goto x; // expected-error {{cannot jump}}
293 goto x; // expected-error {{cannot jump}}
294 const S &s = S(); // expected-note {{jump bypasses variable initialization}}
299 #if __cplusplus >= 201103L
301 struct S { int get(); private: int n; };
303 goto x; // expected-error {{cannot jump}}
304 S s = {}; // expected-note {{jump bypasses variable initialization}}
312 struct B { const int &r; const A &a; };
317 B b = { 0, a }; // ok
322 x: // expected-note {{possible target of indirect goto}}
323 B b = { 0, A() }; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
324 goto *p; // expected-error {{cannot jump}}
328 #if __cplusplus >= 201103L
330 typedef decltype(sizeof(int)) size_t;
331 template<typename T> struct initializer_list {
334 initializer_list(const T *, size_t);
343 x: // expected-note {{possible target of indirect goto}}
344 std::initializer_list<A> il = { a }; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
345 goto *p; // expected-error {{cannot jump}}
359 std::initializer_list<B> il = {
368 x: // expected-note {{possible target of indirect goto}}
369 std::initializer_list<B> il = {
371 { A() } // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
373 goto *p; // expected-error {{cannot jump}}
379 template<typename T> void f() {
380 goto x; // expected-error {{cannot jump}}
381 T t; // expected-note {{bypasses}}
385 template void f<int>();
387 template void f<X>(); // expected-note {{instantiation of}}
393 template <typename T>
405 template<typename TT>
406 static void foo(const Source &SF, MyCl<TT *> Source::*m) {
407 switch (SF.getKind()) {
414 auto &y = const_cast<MyCl<TT *> &>(SF.*m); // expected-warning 0-1{{extension}}
418 int Source::getKind() const {
419 foo(*this, &Source::m);
424 namespace test_recovery {
425 // Test that jump scope checking recovers when there are unspecified errors
426 // in the function declaration or body.
428 void test(nexist, int c) { // expected-error {{}}
429 nexist_fn(); // expected-error {{}}
430 goto nexist_label; // expected-error {{use of undeclared label}}
431 goto a0; // expected-error {{cannot jump}}
432 int a = 0; // expected-note {{jump bypasses variable initialization}}
436 case $: // expected-error {{}}
438 int x = 56; // expected-note {{jump bypasses variable initialization}}
439 case 1: // expected-error {{cannot jump}}
447 // Jumping into SEH try blocks is not permitted.
449 void jump_into_except() {
450 goto into_try_except_try; // expected-error {{cannot jump from this goto statement to its label}}
451 __try { // expected-note {{jump bypasses initialization of __try block}}
457 goto into_try_except_except; // expected-error {{cannot jump from this goto statement to its label}}
459 } __except(0) { // expected-note {{jump bypasses initialization of __except block}}
460 into_try_except_except:
465 void jump_into_finally() {
466 goto into_try_except_try; // expected-error {{cannot jump from this goto statement to its label}}
467 __try { // expected-note {{jump bypasses initialization of __try block}}
473 goto into_try_except_finally; // expected-error {{cannot jump from this goto statement to its label}}
475 } __finally { // expected-note {{jump bypasses initialization of __finally block}}
476 into_try_except_finally:
481 // Jumping out of SEH try blocks ok in general. (Jumping out of a __finally
482 // has undefined behavior.)
484 void jump_out_of_except() {
486 goto out_of_except_try;
494 goto out_of_except_except;
496 out_of_except_except:
500 void jump_out_of_finally() {
502 goto out_of_finally_try;
510 goto out_of_finally_finally; // expected-warning {{jump out of __finally block has undefined behavior}}
515 goto *&&out_of_finally_finally; // expected-warning {{jump out of __finally block has undefined behavior}}
517 out_of_finally_finally:
521 // Jumping between protected scope and handler is not permitted.
523 void jump_try_except() {
525 goto from_try_to_except; // expected-error {{cannot jump from this goto statement to its label}}
526 } __except(0) { // expected-note {{jump bypasses initialization of __except block}}
531 __try { // expected-note {{jump bypasses initialization of __try block}}
535 goto from_except_to_try; // expected-error {{cannot jump from this goto statement to its label}}
539 void jump_try_finally() {
541 goto from_try_to_finally; // expected-error {{cannot jump from this goto statement to its label}}
542 } __finally { // expected-note {{jump bypasses initialization of __finally block}}
547 __try { // expected-note {{jump bypasses initialization of __try block}}
551 goto from_finally_to_try; // expected-error {{cannot jump from this goto statement to its label}} expected-warning {{jump out of __finally block has undefined behavior}}
556 // These are not permitted.
560 goto outer_except; // expected-error {{cannot jump from this goto statement to its label}}
562 } __except(0) { // expected-note {{jump bypasses initialization of __except bloc}}
570 goto outer_finally; // expected-error {{cannot jump from this goto statement to its label}}
572 } __finally { // expected-note {{jump bypasses initialization of __finally bloc}}
577 // These are permitted.
581 goto after_outer_except; // expected-warning {{jump out of __finally block has undefined behavior}}
591 goto after_outer_finally;
599 // This section is academic, as MSVC doesn't support indirect gotos.
601 void indirect_jumps(void **ip) {
602 static void *ips[] = { &&l };
604 __try { // expected-note {{jump exits __try block}}
605 // FIXME: Should this be allowed? Jumping out of the guarded section of a
606 // __try/__except doesn't require unwinding.
607 goto *ip; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
612 } __except(0) { // expected-note {{jump exits __except block}}
613 // FIXME: What about here?
614 goto *ip; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
617 __try { // expected-note {{jump exits __try block}}
618 goto *ip; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
623 } __finally { // expected-note {{jump exits __finally block}}
624 goto *ip; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
626 l: // expected-note 4 {{possible target of indirect goto statement}}