Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/constexpr-nonlit11.C

raw
1 // PR c++/106649
2 // P2448 - Relaxing some constexpr restrictions
3 // { dg-do compile { target c++23 } }
4 // { dg-options "-Winvalid-constexpr -pedantic-errors" }
5
6 // [dcl.constexpr]/4 used to say:
7 // The definition of a constexpr constructor whose function-body
8 // is not = delete shall additionally satisfy the following requirements:
9 // (4.1) for a non-delegating constructor, every constructor selected to initialize non-static data members and base class subobjects shall be a constexpr constructor;
10 // (4.2) for a delegating constructor, the target constructor shall be a constexpr constructor.
11
12 // This continues to be OK.
13 struct Length {
14 constexpr explicit Length(int i = 0) : val(i) { }
15 private:
16 int val;
17 };
18
19 struct X {
20 X() {}
21 X(int i_) : i(i_) {}
22 int i;
23 };
24
25 struct S {
26 X x;
27 // Calls a non-constexpr constructor X::X(int).
28 constexpr S(int i) : x(i) { } // { dg-warning "call to" "" { target { ! implicit_constexpr } } }
29 S(int, int) { }
30 // Target constructor isn't constexpr.
31 constexpr S() : S(42, 42) { } // { dg-warning "call to" "" { target { ! implicit_constexpr } } }
32 };
33
34 namespace N1 {
35 struct X {
36 void x();
37 };
38 struct Y {
39 X x;
40 constexpr void y() { x.x(); } // { dg-warning "call to" }
41 };
42 }
43
44 void g();
45
46 struct A {
47 constexpr A() { g(); } // { dg-warning "call to" }
48 };
49
50 struct B {
51 constexpr B& operator=(const B&) { g(); return *this; } // { dg-warning "call to" }
52 constexpr B& operator=(B&&) { g(); return *this; } // { dg-warning "call to" }
53 };