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
) { // do not warn that 'something_invalid' is not listed;
197 // 'what_am_i_thinking' might have been intended to be that case.
198 case something_valid
:
199 case what_am_i_thinking
: // expected-error {{use of undeclared identifier}}
211 static void *ps
[] = { &&a0
};
212 goto *&&a0
; // expected-error {{cannot jump}}
213 int a
= 3; // expected-note {{jump bypasses variable initialization}}
226 static void *ips
[] = { &&l0
};
227 l0
: // expected-note {{possible target of indirect goto}}
228 C c0
= 42; // expected-note {{jump exits scope of variable with non-trivial destructor}}
229 goto *ip
; // expected-error {{cannot jump}}
239 static void *ips
[] = { &&l0
};
241 l0
: // expected-note {{possible target of indirect goto}}
242 const C
&c1
= 42; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
244 goto *ip
; // expected-error {{cannot jump}}
255 static void *ips
[] = { &&l0
};
256 l0
: // expected-note {{possible target of indirect goto}}
257 const int &c1
= C(1).i
; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
258 goto *ip
; // expected-error {{cannot jump}}
266 operator int&() const;
269 static void *ips
[] = { &&l0
};
271 // no warning since the C temporary is destructed before the goto.
272 const int &c1
= C(1);
280 goto x
; // expected-error {{cannot jump}}
281 } catch(...) { // expected-note {{jump bypasses initialization of catch block}}
284 void f2() try { // expected-note {{jump bypasses initialization of try block}}
287 goto x
; // expected-error {{cannot jump}}
294 goto x
; // expected-error {{cannot jump}}
295 const S
&s
= S(); // expected-note {{jump bypasses variable initialization}}
300 #if __cplusplus >= 201103L
302 struct S
{ int get(); private: int n
; };
304 goto x
; // expected-error {{cannot jump}}
305 S s
= {}; // expected-note {{jump bypasses variable initialization}}
313 struct B
{ const int &r
; const A
&a
; };
318 B b
= { 0, a
}; // ok
323 x
: // expected-note {{possible target of indirect goto}}
324 B b
= { 0, A() }; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
325 goto *p
; // expected-error {{cannot jump}}
329 #if __cplusplus >= 201103L
331 typedef decltype(sizeof(int)) size_t;
332 template<typename T
> struct initializer_list
{
335 initializer_list(const T
*, size_t);
344 x
: // expected-note {{possible target of indirect goto}}
345 std::initializer_list
<A
> il
= { a
}; // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
346 goto *p
; // expected-error {{cannot jump}}
360 std::initializer_list
<B
> il
= {
369 x
: // expected-note {{possible target of indirect goto}}
370 std::initializer_list
<B
> il
= {
372 { A() } // expected-note {{jump exits scope of lifetime-extended temporary with non-trivial destructor}}
374 goto *p
; // expected-error {{cannot jump}}
380 template<typename T
> void f() {
381 goto x
; // expected-error {{cannot jump}}
382 T t
; // expected-note {{bypasses}}
386 template void f
<int>();
388 template void f
<X
>(); // expected-note {{instantiation of}}
394 template <typename T
>
406 template<typename TT
>
407 static void foo(const Source
&SF
, MyCl
<TT
*> Source::*m
) {
408 switch (SF
.getKind()) {
415 auto &y
= const_cast<MyCl
<TT
*> &>(SF
.*m
); // expected-warning 0-1{{extension}}
419 int Source::getKind() const {
420 foo(*this, &Source::m
);
425 namespace test_recovery
{
426 // Test that jump scope checking recovers when there are unspecified errors
427 // in the function declaration or body.
429 void test(nexist
, int c
) { // expected-error {{}}
430 nexist_fn(); // expected-error {{}}
431 goto nexist_label
; // expected-error {{use of undeclared label}}
432 goto a0
; // expected-error {{cannot jump}}
433 int a
= 0; // expected-note {{jump bypasses variable initialization}}
437 case $
: // expected-error {{}}
439 int x
= 56; // expected-note {{jump bypasses variable initialization}}
440 case 1: // expected-error {{cannot jump}}
448 // Jumping into SEH try blocks is not permitted.
450 void jump_into_except() {
451 goto into_try_except_try
; // expected-error {{cannot jump from this goto statement to its label}}
452 __try
{ // expected-note {{jump bypasses initialization of __try block}}
458 goto into_try_except_except
; // expected-error {{cannot jump from this goto statement to its label}}
460 } __except(0) { // expected-note {{jump bypasses initialization of __except block}}
461 into_try_except_except
:
466 void jump_into_finally() {
467 goto into_try_except_try
; // expected-error {{cannot jump from this goto statement to its label}}
468 __try
{ // expected-note {{jump bypasses initialization of __try block}}
474 goto into_try_except_finally
; // expected-error {{cannot jump from this goto statement to its label}}
476 } __finally
{ // expected-note {{jump bypasses initialization of __finally block}}
477 into_try_except_finally
:
482 // Jumping out of SEH try blocks ok in general. (Jumping out of a __finally
483 // has undefined behavior.)
485 void jump_out_of_except() {
487 goto out_of_except_try
;
495 goto out_of_except_except
;
497 out_of_except_except
:
501 void jump_out_of_finally() {
503 goto out_of_finally_try
;
511 goto out_of_finally_finally
; // expected-warning {{jump out of __finally block has undefined behavior}}
516 goto *&&out_of_finally_finally
; // expected-warning {{jump out of __finally block has undefined behavior}}
518 out_of_finally_finally
:
522 // Jumping between protected scope and handler is not permitted.
524 void jump_try_except() {
526 goto from_try_to_except
; // expected-error {{cannot jump from this goto statement to its label}}
527 } __except(0) { // expected-note {{jump bypasses initialization of __except block}}
532 __try
{ // expected-note {{jump bypasses initialization of __try block}}
536 goto from_except_to_try
; // expected-error {{cannot jump from this goto statement to its label}}
540 void jump_try_finally() {
542 goto from_try_to_finally
; // expected-error {{cannot jump from this goto statement to its label}}
543 } __finally
{ // expected-note {{jump bypasses initialization of __finally block}}
548 __try
{ // expected-note {{jump bypasses initialization of __try block}}
552 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}}
557 // These are not permitted.
561 goto outer_except
; // expected-error {{cannot jump from this goto statement to its label}}
563 } __except(0) { // expected-note {{jump bypasses initialization of __except bloc}}
571 goto outer_finally
; // expected-error {{cannot jump from this goto statement to its label}}
573 } __finally
{ // expected-note {{jump bypasses initialization of __finally bloc}}
578 // These are permitted.
582 goto after_outer_except
; // expected-warning {{jump out of __finally block has undefined behavior}}
592 goto after_outer_finally
;
600 // This section is academic, as MSVC doesn't support indirect gotos.
602 void indirect_jumps(void **ip
) {
603 static void *ips
[] = { &&l
};
605 __try
{ // expected-note {{jump exits __try block}}
606 // FIXME: Should this be allowed? Jumping out of the guarded section of a
607 // __try/__except doesn't require unwinding.
608 goto *ip
; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
613 } __except(0) { // expected-note {{jump exits __except block}}
614 // FIXME: What about here?
615 goto *ip
; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
618 __try
{ // expected-note {{jump exits __try block}}
619 goto *ip
; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
624 } __finally
{ // expected-note {{jump exits __finally block}}
625 goto *ip
; // expected-error {{cannot jump from this indirect goto statement to one of its possible targets}}
627 l
: // expected-note 4 {{possible target of indirect goto statement}}
633 void continue_scope_check() {
635 for (; ({break; true;});) {}
636 for (; ({continue; true;});) {}
637 for (; int n
= ({break; 0;});) {}
638 for (; int n
= 0; ({break;})) {}
639 for (; int n
= 0; ({continue;})) {}
641 // This would jump past the initialization of 'n' to the increment (where 'n'
643 for (; int n
= ({continue; 0;});) {} // expected-error {{cannot jump from this continue statement to the loop increment; jump bypasses initialization of loop condition variable}}
645 // An intervening loop makes it OK again.
646 for (; int n
= ({while (true) continue; 0;});) {}