| 1 |
// { dg-do compile { target c++14 } } |
| 2 |
// Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'. |
| 3 |
|
| 4 |
constexpr void f1() { |
| 5 |
if (false) |
| 6 |
throw; |
| 7 |
} |
| 8 |
|
| 9 |
constexpr void f2() { |
| 10 |
if (true) |
| 11 |
throw; // { dg-error "not a constant expression" "" { target c++20_down } } |
| 12 |
} |
| 13 |
|
| 14 |
constexpr void f3() { |
| 15 |
if (false) |
| 16 |
; |
| 17 |
else |
| 18 |
throw; // { dg-error "not a constant expression" "" { target c++20_down } } |
| 19 |
} |
| 20 |
|
| 21 |
constexpr void f4() { |
| 22 |
throw; // { dg-error "not a constant expression" "" { target c++20_down } } |
| 23 |
} |
| 24 |
|
| 25 |
constexpr int fun(int n) { |
| 26 |
switch (n) { |
| 27 |
case 0: |
| 28 |
return 1; |
| 29 |
default: |
| 30 |
throw; // { dg-error "not a constant expression" } |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
static_assert(fun(0), ""); |
| 35 |
static_assert(fun(1), ""); // { dg-error "non-constant|in .constexpr. expansion of" } |