| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 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|call to consteval function" } |
| 20 |
constexpr int f7 (int x) { return f6 (x); } // { dg-error "'x' is not a constant expression|call to consteval function" } |
| 21 |
constexpr int f = f7 (5); |
| 22 |
using fnptr = int (int); |
| 23 |
fnptr *g = f6; // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" } |
| 24 |
int f8 (fnptr *); |
| 25 |
int h = f8 (f6); // { dg-error "taking address of an immediate function 'consteval int f6\\(int\\)'" } |
| 26 |
consteval constexpr int f9 () { return 0; } // { dg-error "both 'constexpr' and 'consteval' specified" } |
| 27 |
constexpr consteval int f10 () { return 0; } // { dg-error "both 'constexpr' and 'consteval' specified" } |
| 28 |
consteval consteval int f11 () { return 0; } // { dg-error "duplicate 'consteval'" } |
| 29 |
struct U { consteval ~U () {} }; // { dg-error "a destructor cannot be 'consteval'" } |
| 30 |
struct V { consteval int v = 5; }; // { dg-error "non-static data member 'v' declared 'consteval'" } |
| 31 |
struct W { consteval static int w; }; // { dg-error "static data member 'w' declared 'consteval'" } |
| 32 |
int i = sizeof (&f6); // { dg-bogus "taking address of an immediate function 'consteval int f6\\(int\\)'" } |
| 33 |
using j = decltype (&f6); // { dg-bogus "taking address of an immediate function 'consteval int f6\\(int\\)'" } |
| 34 |
int k = sizeof (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" } |
| 35 |
using l = decltype (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" } |
| 36 |
bool m = noexcept (f6 (d)); // { dg-bogus "the value of 'd' is not usable in a constant expression" } |
| 37 |
namespace std { |
| 38 |
using size_t = decltype (sizeof (0)); |
| 39 |
} |
| 40 |
consteval void* operator new (std::size_t); // { dg-error "'operator new' cannot be 'consteval'" } |
| 41 |
consteval void operator delete (void *, std::size_t) noexcept; // { dg-error "'operator delete' cannot be 'consteval'" } |
| 42 |
consteval void operator delete[] (void *) noexcept; // { dg-error "'operator delete \\\[\\\]' cannot be 'consteval'" } |
| 43 |
struct X { |
| 44 |
static consteval void* operator new (std::size_t); // { dg-error "'operator new' cannot be 'consteval'" } |
| 45 |
static consteval void operator delete (void *, std::size_t) noexcept; // { dg-error "'operator delete' cannot be 'consteval'" } |
| 46 |
consteval static void operator delete[] (void *) noexcept; // { dg-error "'operator delete \\\[\\\]' cannot be 'consteval'" } |
| 47 |
}; |
| 48 |
consteval int main () { return 0; } // { dg-error "cannot declare '::main' to be 'consteval'" } |
| 49 |
struct A { A (); int a; }; // { dg-message "defaulted constructor calls non-'constexpr' 'A::A\\(\\)'" } |
| 50 |
struct B { constexpr B () : b (0) {} int b; }; |
| 51 |
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'" } |
| 52 |
struct D { B b; consteval D () = default; }; |
| 53 |
template <class T> consteval T f12 (T x) { return x; } |
| 54 |
template consteval float f12 (float x); // { dg-error "explicit instantiation shall not use 'consteval' specifier" } |
| 55 |
consteval int |
| 56 |
f13 (int x) |
| 57 |
{ |
| 58 |
static int a = 5; // { dg-error "'a' defined 'static' in 'consteval' function only available with" "" { target c++20_only } } |
| 59 |
thread_local int b = 6; // { dg-error "'b' defined 'thread_local' in 'consteval' function only available with" "" { target c++20_only } } |
| 60 |
return x; |
| 61 |
} |