| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wjump-misses-init %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wc++-compat %s |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify=good %s |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -verify=good -fms-compatibility %s |
| 5 |
// RUN: %clang_cc1 -fsyntax-only -verify=cxx,both -x c++ %s |
| 6 |
// good-no-diagnostics |
| 7 |
|
| 8 |
void goto_func_1(void) { |
| 9 |
goto ouch; // c-warning {{jump from this goto statement to its label is incompatible with C++}} \ |
| 10 |
cxx-error {{cannot jump from this goto statement to its label}} |
| 11 |
int i = 12; // both-note {{jump bypasses variable initialization}} |
| 12 |
|
| 13 |
ouch: |
| 14 |
; |
| 15 |
} |
| 16 |
|
| 17 |
void goto_func_2(void) { |
| 18 |
goto ouch; |
| 19 |
static int i = 12; // This initialization is not jumped over, so no warning. |
| 20 |
|
| 21 |
ouch: |
| 22 |
; |
| 23 |
} |
| 24 |
|
| 25 |
void switch_func(int i) { |
| 26 |
switch (i) { |
| 27 |
int x = 12; // both-note {{jump bypasses variable initialization}} |
| 28 |
case 0: // c-warning {{jump from switch statement to this case label is incompatible with C++}} \ |
| 29 |
cxx-error {{cannot jump from switch statement to this case label}} |
| 30 |
break; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// Statement expressions are a bit strange in that they seem to allow for |
| 35 |
// jumping past initialization without being diagnosed, even in C++. Perhaps |
| 36 |
// this should change? |
| 37 |
void f(void) { |
| 38 |
({ |
| 39 |
goto ouch; |
| 40 |
int i = 12; |
| 41 |
}); |
| 42 |
|
| 43 |
for (int i = ({ goto ouch; int x = 10; x;}); i < 0; ++i) { |
| 44 |
} |
| 45 |
|
| 46 |
ouch: |
| 47 |
; |
| 48 |
} |
| 49 |
|
| 50 |
void indirect(int n) { |
| 51 |
DirectJump: |
| 52 |
; |
| 53 |
|
| 54 |
void *Table[] = {&&DirectJump, &&Later}; |
| 55 |
goto *Table[n]; // c-warning {{jump from this indirect goto statement to one of its possible targets is incompatible with C++}} \ |
| 56 |
cxx-error {{cannot jump from this indirect goto statement to one of its possible targets}} |
| 57 |
|
| 58 |
int x = 12; // both-note {{jump bypasses variable initialization}} |
| 59 |
Later: // both-note {{possible target of indirect goto statement}} |
| 60 |
; |
| 61 |
} |