| 1 |
// P2324R2 - Labels at the end of compound statements |
| 2 |
// PR c++/103539 |
| 3 |
// { dg-do compile } |
| 4 |
// Test good cases. |
| 5 |
|
| 6 |
void |
| 7 |
p2324 () |
| 8 |
{ |
| 9 |
first: |
| 10 |
int x; |
| 11 |
second: |
| 12 |
x = 1; |
| 13 |
last: |
| 14 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 15 |
|
| 16 |
void |
| 17 |
fn1 () |
| 18 |
{ |
| 19 |
l1: |
| 20 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 21 |
|
| 22 |
void |
| 23 |
fn2 () |
| 24 |
{ |
| 25 |
if (1) |
| 26 |
{ |
| 27 |
l1: |
| 28 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 29 |
} |
| 30 |
|
| 31 |
void |
| 32 |
fn3 () |
| 33 |
{ |
| 34 |
{ |
| 35 |
{ |
| 36 |
label: |
| 37 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
fn4 () |
| 43 |
{ |
| 44 |
switch (1) |
| 45 |
{ |
| 46 |
lab: |
| 47 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
fn5 () |
| 52 |
{ |
| 53 |
l1: |
| 54 |
l2: |
| 55 |
l3: |
| 56 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 57 |
|
| 58 |
void |
| 59 |
fn6 () |
| 60 |
{ |
| 61 |
; |
| 62 |
l1: |
| 63 |
l2: |
| 64 |
l3: |
| 65 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 66 |
|
| 67 |
|
| 68 |
#if __cplusplus >= 201103L |
| 69 |
void |
| 70 |
fn7 () |
| 71 |
{ |
| 72 |
auto l = [](){ |
| 73 |
lab: |
| 74 |
}; // { dg-error "label at end of compound statement only available with" "" { target { c++20_down && c++11 } } } |
| 75 |
} |
| 76 |
#endif |
| 77 |
|
| 78 |
void |
| 79 |
fn8 () |
| 80 |
{ |
| 81 |
try |
| 82 |
{ |
| 83 |
lab1: |
| 84 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 85 |
catch (int) |
| 86 |
{ |
| 87 |
lab2: |
| 88 |
} // { dg-error "label at end of compound statement only available with" "" { target c++20_down } } |
| 89 |
} |