2 // P2448 - Relaxing some constexpr restrictions
3 // { dg-do compile { target c++23 } }
4 // { dg-options "-Winvalid-constexpr -pedantic-errors" }
6 // No constexpr constructors = not a literal type.
11 // C++23: It is possible to write a constexpr function for which no
12 // invocation satisfies the requirements of a core constant expression.
14 fn0 (int) // { dg-warning "invalid return type" "" { target { ! implicit_constexpr } } }
20 fn1 (NonLiteral) // { dg-warning "invalid type" "" { target { ! implicit_constexpr } } }
30 constexpr void g(int& i) {
31 f(i); // { dg-warning "call to" }
34 // [dcl.constexpr] used to have this.
35 constexpr int f(bool b)
36 { return b ? throw 0 : 0; } // OK
37 constexpr int f() { return f(true); } // ill-formed, no diagnostic required
40 constexpr B(int) : i(0) { }
47 constexpr D() : B(global) { } // { dg-warning "not usable" }
48 // ill-formed, no diagnostic required
49 // lvalue-to-rvalue conversion on non-constant global
52 // If no specialization of the template would satisfy the requirements
53 // for a constexpr function when considered as a non-template function,
54 // the template is ill-formed, no diagnostic required.
69 constexpr volatile int cvi = 10;
74 return cvi; // { dg-warning "lvalue-to-rvalue conversion" }
77 constexpr unsigned int
80 unsigned int *q = reinterpret_cast<unsigned int *>(p); // { dg-warning "reinterpret_cast" }
87 void *p = (void *) 1LL; // { dg-warning ".reinterpret_cast. from integer to pointer" }
94 static int s = i; // { dg-warning "static" }