c++: P0847R7 (deducing this) - xobj lambdas. [PR102609]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp2a / consteval-prop6.C
blobca7db7c63d37e08eb13a507bfc4ccc66ece3c90c
1 // P2564R3
2 // { dg-do compile { target c++20 } }
3 // From cxx2b-consteval-propagate.cpp.
5 void side_effect();
7 consteval int
8 f (int x)
10   if (!x)
11     side_effect(); // { dg-error "call to non-.constexpr. function" }
12   return x;
15 struct SS {
16   int y = f(1);
17   int x = f(0);
18   SS();
20 SS::SS(){} // { dg-error "call to consteval function" }
22 consteval int
23 f2 (int x)
25   if (!__builtin_is_constant_evaluated ())
26     side_effect();
27   return x;
30 struct S2 {
31   int x = f2(0);
32   constexpr S2();
35 constexpr S2::S2(){}
36 S2 s = {};
37 constinit S2 s2 = {};
39 struct S3 {
40   int x = f2(0);
41   S3();
43 S3::S3(){}
45 consteval int undef (int x); // { dg-warning "never defined" }
47 struct X {
48   int a = sizeof(undef(0));
49   int x = undef(0);
51   X() = default; // { dg-error {'consteval int undef\(int\)' used before its definition} }
54 void
55 test ()
57   [[maybe_unused]] X x; // { dg-error "call to consteval function" }
58 // { dg-message "promoted to an immediate function" "" { target *-*-* } .-1 }