| 1 |
/* N3356 - if declarations. */ |
| 2 |
/* PR c/117019 */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-std=c2y -Wall -Wextra" } */ |
| 5 |
/* Test VLAs. Invalid code. */ |
| 6 |
|
| 7 |
void foo (int) { } |
| 8 |
|
| 9 |
void |
| 10 |
g () |
| 11 |
{ |
| 12 |
int i = 3; |
| 13 |
|
| 14 |
switch (i) /* { dg-message "switch starts here" } */ |
| 15 |
{ /* { dg-warning "statement will never be executed" } */ |
| 16 |
int arr[i] = { }; |
| 17 |
default: /* { dg-error "switch jumps into scope" } */ |
| 18 |
i = arr[0]; |
| 19 |
break; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
void |
| 24 |
g2 (int i) |
| 25 |
{ |
| 26 |
goto L1; /* { dg-error "jump into scope" } */ |
| 27 |
if (int arr[i] = { }; arr[0]) |
| 28 |
{ |
| 29 |
L1: |
| 30 |
} |
| 31 |
|
| 32 |
goto L2; /* { dg-error "jump into scope" } */ |
| 33 |
if (int arr[i] = { }) /* { dg-warning "will always evaluate as .true." } */ |
| 34 |
{ |
| 35 |
L2: |
| 36 |
arr[0] = 42; |
| 37 |
} |
| 38 |
|
| 39 |
goto L3; /* { dg-error "jump into scope" } */ |
| 40 |
switch (int arr[i] = { }; arr[0]) |
| 41 |
{ |
| 42 |
case 0: |
| 43 |
L3: |
| 44 |
return; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
void |
| 49 |
g3 (int i, int n) |
| 50 |
{ |
| 51 |
switch (i) |
| 52 |
{ |
| 53 |
case 0: |
| 54 |
if (int arr[n] = { }) /* { dg-warning "will always evaluate as .true." } */ |
| 55 |
{ |
| 56 |
case 3: /* { dg-error "switch jumps into scope" } */ |
| 57 |
arr[0] = 42; |
| 58 |
} |
| 59 |
break; |
| 60 |
default: |
| 61 |
return; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
void |
| 66 |
g4 (int i, int n) |
| 67 |
{ |
| 68 |
switch (i) |
| 69 |
{ |
| 70 |
case 0: |
| 71 |
if (int arr[n] = { }; arr[0]) |
| 72 |
{ |
| 73 |
case 3: /* { dg-error "switch jumps into scope" } */ |
| 74 |
} |
| 75 |
break; |
| 76 |
default: |
| 77 |
return; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
void |
| 82 |
g5 (int i, int n) |
| 83 |
{ |
| 84 |
switch (i) |
| 85 |
{ |
| 86 |
case 0: |
| 87 |
goto L; /* { dg-error "jump into scope" } */ |
| 88 |
switch (int arr[n] = { }; arr[0]) |
| 89 |
{ |
| 90 |
L: |
| 91 |
} |
| 92 |
break; |
| 93 |
default: |
| 94 |
return; |
| 95 |
} |
| 96 |
} |