| 1 |
// P2564R3 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// Test default arguments. |
| 4 |
|
| 5 |
consteval int id (int i) { return i; } |
| 6 |
|
| 7 |
template<typename> |
| 8 |
constexpr int |
| 9 |
f1 (int i = id (42)) |
| 10 |
{ |
| 11 |
return i; |
| 12 |
} |
| 13 |
|
| 14 |
int non_const; // { dg-message ".int non_const. is not const" } |
| 15 |
|
| 16 |
template<typename> |
| 17 |
constexpr int |
| 18 |
f2 (int i = id (non_const)) |
| 19 |
{ |
| 20 |
return i; |
| 21 |
} |
| 22 |
|
| 23 |
constexpr int |
| 24 |
f3 (auto) |
| 25 |
{ |
| 26 |
return f2<int>(); // { dg-message "contains an immediate-escalating expression .id\\(non_const\\)." } |
| 27 |
} |
| 28 |
|
| 29 |
auto a = &f3<int>; // { dg-error "taking address of an immediate function" } |
| 30 |
|
| 31 |
void |
| 32 |
g (int i) |
| 33 |
{ |
| 34 |
f1<int> (42); |
| 35 |
f1<int> (i); |
| 36 |
f1<int> (); |
| 37 |
f2<int> (42); |
| 38 |
f2<int> (i); |
| 39 |
f2<int> (); // { dg-error "call to consteval function .id\\(non_const\\). is not a constant expression" } |
| 40 |
// { dg-error ".non_const. is not usable in a constant expression" "" { target *-*-* } .-1 } |
| 41 |
} |