| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-std=c++2b" } |
| 3 |
|
| 4 |
int qux (); |
| 5 |
|
| 6 |
constexpr int |
| 7 |
foo (int x) |
| 8 |
{ |
| 9 |
switch (x) |
| 10 |
{ |
| 11 |
static const int v = 6; |
| 12 |
case 12: |
| 13 |
return v; |
| 14 |
} |
| 15 |
return 0; |
| 16 |
} |
| 17 |
|
| 18 |
constexpr int |
| 19 |
bar (int x) |
| 20 |
{ |
| 21 |
switch (x) |
| 22 |
{ |
| 23 |
thread_local const int v = 7; |
| 24 |
case 12: |
| 25 |
return 7; |
| 26 |
} |
| 27 |
return 0; |
| 28 |
} |
| 29 |
|
| 30 |
constexpr int |
| 31 |
baz (int x) |
| 32 |
{ |
| 33 |
switch (x) |
| 34 |
{ |
| 35 |
static int v = 6; // { dg-message "int v' is not const" } |
| 36 |
case 12: |
| 37 |
return v; // { dg-error "the value of 'v' is not usable in a constant expression" } |
| 38 |
} |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
constexpr int |
| 43 |
corge (int x) |
| 44 |
{ |
| 45 |
switch (x) |
| 46 |
{ |
| 47 |
thread_local int v = 6; // { dg-message "int v' is not const" } |
| 48 |
case 12: |
| 49 |
return v; // { dg-error "the value of 'v' is not usable in a constant expression" } |
| 50 |
} |
| 51 |
return 0; |
| 52 |
} |
| 53 |
|
| 54 |
constexpr int a = foo (12); |
| 55 |
constexpr int b = bar (12); |
| 56 |
constexpr int c = baz (12); |
| 57 |
constexpr int d = corge (12); |