| 1 |
// DR 2406 - [[fallthrough]] attribute and iteration statements |
| 2 |
// PR c++/107571 |
| 3 |
// { dg-do compile { target c++11 } } |
| 4 |
// { dg-options "-pedantic-errors -Wimplicit-fallthrough" } |
| 5 |
|
| 6 |
void bar (); |
| 7 |
void baz (); |
| 8 |
void qux (); |
| 9 |
|
| 10 |
void |
| 11 |
foo (int n) |
| 12 |
{ |
| 13 |
switch (n) |
| 14 |
{ |
| 15 |
case 1: |
| 16 |
case 2: |
| 17 |
bar (); |
| 18 |
[[fallthrough]]; |
| 19 |
case 3: |
| 20 |
do |
| 21 |
{ |
| 22 |
[[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } |
| 23 |
} |
| 24 |
while (false); |
| 25 |
case 6: |
| 26 |
do |
| 27 |
{ |
| 28 |
[[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } |
| 29 |
} |
| 30 |
while (n--); |
| 31 |
case 7: |
| 32 |
while (false) |
| 33 |
{ |
| 34 |
[[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } |
| 35 |
} |
| 36 |
case 5: |
| 37 |
baz (); // { dg-warning "this statement may fall through" } |
| 38 |
case 4: // { dg-message "here" } |
| 39 |
qux (); |
| 40 |
[[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
corge (int n) |
| 46 |
{ |
| 47 |
switch (n) |
| 48 |
{ |
| 49 |
case 1: |
| 50 |
{ |
| 51 |
int i = 0; |
| 52 |
do |
| 53 |
{ |
| 54 |
[[fallthrough]]; // { dg-error "attribute 'fallthrough' not preceding a case label or default label" } |
| 55 |
} |
| 56 |
while (false); |
| 57 |
} |
| 58 |
case 2: |
| 59 |
bar (); |
| 60 |
break; |
| 61 |
default: |
| 62 |
break; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
fred (int n) |
| 68 |
{ |
| 69 |
switch (n) |
| 70 |
{ |
| 71 |
case 1: |
| 72 |
{ |
| 73 |
int i = 0; |
| 74 |
[[fallthrough]]; |
| 75 |
} |
| 76 |
case 2: |
| 77 |
bar (); |
| 78 |
break; |
| 79 |
default: |
| 80 |
break; |
| 81 |
} |
| 82 |
} |