| 1 |
// { dg-do compile } |
| 2 |
// Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'. |
| 3 |
// { dg-options "-std=c++2a" } |
| 4 |
|
| 5 |
consteval int bar (int i) { if (i != 1) throw 1; return 0; } // { dg-error "is not a constant expression" } |
| 6 |
|
| 7 |
template <int N> |
| 8 |
void foo () |
| 9 |
{ |
| 10 |
int a = bar (N); |
| 11 |
} |
| 12 |
|
| 13 |
template <int N> |
| 14 |
void qux () |
| 15 |
{ |
| 16 |
int a = bar (N); // { dg-message "in 'constexpr' expansion of 'bar\\(2\\)'" } |
| 17 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 18 |
} |
| 19 |
|
| 20 |
// This function is not instantiated so NDR. |
| 21 |
template <int N> |
| 22 |
void quux () |
| 23 |
{ |
| 24 |
int a = bar (5); |
| 25 |
} |
| 26 |
|
| 27 |
void |
| 28 |
baz () |
| 29 |
{ |
| 30 |
foo<1> (); |
| 31 |
qux<2> (); |
| 32 |
} |
| 33 |
|
| 34 |
int a = bar (2); // { dg-message "in 'constexpr' expansion of 'bar\\(2\\)'" } |
| 35 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |