1 // { dg-do compile { target c++20 } }
3 struct S { S () : a (0), b (1) {} int a, b; };
4 int f1 (); // { dg-message "previous declaration 'int f1\\(\\)'" }
5 consteval int f1 (); // { dg-error "redeclaration 'consteval int f1\\(\\)' differs in 'consteval' from previous declaration" }
6 consteval int f2 (); // { dg-message "previous declaration 'consteval int f2\\(\\)'" }
7 int f2 (); // { dg-error "redeclaration 'int f2\\(\\)' differs in 'consteval' from previous declaration" }
8 constexpr int f3 (); // { dg-message "previous declaration 'constexpr int f3\\(\\)'" }
9 consteval int f3 (); // { dg-error "redeclaration 'consteval int f3\\(\\)' differs in 'consteval' from previous declaration" }
10 consteval int f4 (); // { dg-message "previous declaration 'consteval int f4\\(\\)'" }
11 constexpr int f4 (); // { dg-error "redeclaration 'constexpr int f4\\(\\)' differs in 'consteval' from previous declaration" }
12 typedef consteval int cint; // { dg-error "'consteval' cannot appear in a typedef declaration" }
13 consteval struct T { int i; }; // { dg-error "'consteval' cannot be used for type declarations" }
14 consteval int a = 5; // { dg-error "a variable cannot be declared 'consteval'" }
15 consteval auto [ b, c ] = S (); // { dg-error "structured binding declaration cannot be 'consteval'" }
16 int f5 (consteval int x) { return x; } // { dg-error "a parameter cannot be declared 'consteval'" }
17 consteval int f6 (int x) { return x; }
18 int d = 6; // { dg-message "'int d' is not const" }
19 int e = f6 (d); // { dg-error "the value of 'd' is not usable in a constant expression" }
20 constexpr int f7 (int x) { return f6 (x); } // { dg-error "'x' is not a constant expression" }
21 constexpr int f = f7 (5); // { dg-error "" }
22 // { dg-message "in 'constexpr' expansion of" "" { target *-*-* } .-1 }
23 using fnptr = int (int);
24 fnptr *g = f6; // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" }
26 int h = f8 (f6); // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" }
27 consteval constexpr int f9 () { return 0; } // { dg-error "both 'constexpr' and 'consteval' specified" }
28 constexpr consteval int f10 () { return 0; } // { dg-error "both 'constexpr' and 'consteval' specified" }
29 consteval consteval int f11 () { return 0; } // { dg-error "duplicate 'consteval'" }
30 struct U { consteval ~U () {} }; // { dg-error "a destructor cannot be 'consteval'" }
31 struct V { consteval int v = 5; }; // { dg-error "non-static data member 'v' declared 'consteval'" }
32 struct W { consteval static int w; }; // { dg-error "static data member 'w' declared 'consteval'" }
33 int i = sizeof (&f6); // { dg-bogus "taking address of an immediate function 'consteval int f6\\(int\\)'" }
34 using j = decltype (&f6); // { dg-bogus "taking address of an immediate function 'consteval int f6\\(int\\)'" }
35 int k = sizeof (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
36 using l = decltype (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
37 bool m = noexcept (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" }
39 using size_t = decltype (sizeof (0));
41 consteval void* operator new (std::size_t); // { dg-error "'operator new' cannot be 'consteval'" }
42 consteval void operator delete (void *, std::size_t) noexcept; // { dg-error "'operator delete' cannot be 'consteval'" }
43 consteval void operator delete[] (void *) noexcept; // { dg-error "'operator delete \\\[\\\]' cannot be 'consteval'" }
45 static consteval void* operator new (std::size_t); // { dg-error "'operator new' cannot be 'consteval'" }
46 static consteval void operator delete (void *, std::size_t) noexcept; // { dg-error "'operator delete' cannot be 'consteval'" }
47 consteval static void operator delete[] (void *) noexcept; // { dg-error "'operator delete \\\[\\\]' cannot be 'consteval'" }
49 consteval int main () { return 0; } // { dg-error "cannot declare '::main' to be 'consteval'" }
50 struct A { A (); int a; }; // { dg-message "defaulted constructor calls non-'constexpr' 'A::A\\(\\)'" }
51 struct B { constexpr B () : b (0) {} int b; };
52 struct C { A a; consteval C () = default; }; // { dg-error "explicitly defaulted function 'consteval C::C\\(\\)' cannot be declared 'consteval' because the implicit declaration is not 'constexpr'" }
53 struct D { B b; consteval D () = default; };
54 template <class T> consteval T f12 (T x) { return x; }
55 template consteval float f12 (float x); // { dg-error "explicit instantiation shall not use 'consteval' specifier" }
59 static int a = 5; // { dg-error "'a' defined 'static' in 'consteval' function only available with" "" { target c++20_only } }
60 thread_local int b = 6; // { dg-error "'b' defined 'thread_local' in 'consteval' function only available with" "" { target c++20_only } }