testsuite: 32 bit AIX 2 byte wchar
[official-gcc.git] / gcc / testsuite / g++.dg / cpp23 / constexpr-nonlit10.C
blob31d4b873bbf8da94b5b5411bee0d1532cb93f2ed
1 // PR c++/106649
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.
7 struct NonLiteral {
8   NonLiteral() {}
9 };
11 // C++23: It is possible to write a constexpr function for which no
12 // invocation satisfies the requirements of a core constant expression.
13 constexpr NonLiteral
14 fn0 (int) // { dg-warning "invalid return type" "" { target { ! implicit_constexpr } } }
16   return NonLiteral{};
19 constexpr int
20 fn1 (NonLiteral) // { dg-warning "invalid type" "" { target { ! implicit_constexpr } } }
22   return 42;
25 // From P2448.
26 void f(int& i) {
27     i = 0;
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
39 struct B {
40   constexpr B(int) : i(0) { }
41   int i;
44 int global;
46 struct D : B {
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.
55 template<typename>
56 constexpr void
57 fn2 ()
59   int i = 42;
60   f (i);
63 void
64 fn3 ()
66   fn2<int>();
69 constexpr volatile int cvi = 10;
71 constexpr int
72 fn4 ()
74   return cvi;  // { dg-warning "lvalue-to-rvalue conversion" }
77 constexpr unsigned int
78 fn5 (int *p)
80   unsigned int *q = reinterpret_cast<unsigned int *>(p); // { dg-warning "reinterpret_cast" }
81   return *q;
84 constexpr int
85 fn6 (int i)
87   void *p = (void *) 1LL; // { dg-warning ".reinterpret_cast. from integer to pointer" }
88   return 42;
91 constexpr int
92 fn7 (int i)
94   static int s = i; // { dg-warning "static" }
95   return s;