| 1 |
// P2647R1 - Permitting static constexpr variables in constexpr functions |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
constexpr int |
| 5 |
f1 (int x) |
| 6 |
{ |
| 7 |
if (x) |
| 8 |
throw 1; |
| 9 |
return 0; |
| 10 |
} |
| 11 |
|
| 12 |
constexpr int |
| 13 |
f2 () |
| 14 |
{ |
| 15 |
static const int a = f1 (1); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } } |
| 16 |
return 0; |
| 17 |
} |
| 18 |
|
| 19 |
constexpr int |
| 20 |
f3 () |
| 21 |
{ |
| 22 |
static const int a = 5; // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } } |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
constexpr int |
| 27 |
f4 () |
| 28 |
{ // { dg-message "is not usable as a 'constexpr' function because:" "" { target c++23 } .-1 } |
| 29 |
static const int a = f1 (1); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } } |
| 30 |
return 0; // { dg-error "'a' defined 'static' in 'constexpr' context" "" { target c++23 } .-1 } |
| 31 |
} |
| 32 |
|
| 33 |
constexpr int a4 = f4 (); // { dg-error "called in a constant expression" } |
| 34 |
|
| 35 |
constexpr int |
| 36 |
f5 () |
| 37 |
{ |
| 38 |
static const int a = f1 (0); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } } |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
constexpr int |
| 43 |
f6 () |
| 44 |
{ |
| 45 |
static const int a = f1 (0); // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } } |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
constexpr int a6 = f6 (); // { dg-error "called in a constant expression" "" { target c++20_down } } |