| 1 |
// P2564R3 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// From cxx2b-consteval-propagate.cpp. |
| 4 |
|
| 5 |
void side_effect(); |
| 6 |
|
| 7 |
consteval int |
| 8 |
f (int x) |
| 9 |
{ |
| 10 |
if (!x) |
| 11 |
side_effect(); // { dg-error "call to non-.constexpr. function" } |
| 12 |
return x; |
| 13 |
} |
| 14 |
|
| 15 |
struct SS { |
| 16 |
int y = f(1); |
| 17 |
int x = f(0); |
| 18 |
SS(); |
| 19 |
}; |
| 20 |
SS::SS(){} // { dg-error "call to consteval function" } |
| 21 |
|
| 22 |
consteval int |
| 23 |
f2 (int x) |
| 24 |
{ |
| 25 |
if (!__builtin_is_constant_evaluated ()) |
| 26 |
side_effect(); |
| 27 |
return x; |
| 28 |
} |
| 29 |
|
| 30 |
struct S2 { |
| 31 |
int x = f2(0); |
| 32 |
constexpr S2(); |
| 33 |
}; |
| 34 |
|
| 35 |
constexpr S2::S2(){} |
| 36 |
S2 s = {}; |
| 37 |
constinit S2 s2 = {}; |
| 38 |
|
| 39 |
struct S3 { |
| 40 |
int x = f2(0); |
| 41 |
S3(); |
| 42 |
}; |
| 43 |
S3::S3(){} |
| 44 |
|
| 45 |
consteval int undef (int x); // { dg-warning "never defined" } |
| 46 |
|
| 47 |
struct X { |
| 48 |
int a = sizeof(undef(0)); |
| 49 |
int x = undef(0); |
| 50 |
|
| 51 |
X() = default; // { dg-error {'consteval int undef\(int\)' used before its definition} } |
| 52 |
}; |
| 53 |
|
| 54 |
void |
| 55 |
test () |
| 56 |
{ |
| 57 |
[[maybe_unused]] X x; // { dg-error "call to consteval function" } |
| 58 |
// { dg-message "promoted to an immediate function" "" { target *-*-* } .-1 } |
| 59 |
} |