https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128088
Bug ID: 128088
Summary: Member with consteval ctor rejected
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
struct A { constexpr A () : a (42) {} constexpr A (int x) : a (x) {} int a; };
struct B { consteval B () : b (42) {} consteval B (int x) : b (x) {} int b; };
struct C { B c; constexpr C () : c (1) {} };
constexpr C c;
clang++ accepts this with e.g. -std=c++26, but g++ rejects:
test.C: In constructor ‘constexpr C::C()’:
test.C:3:34: error: call to consteval function ‘((C*)this)->C::c.B::B(1)’ is
not a constant expression
3 | struct C { B c; constexpr C () : c (1) {} };
| ^~~~~
test.C:3:34: in ‘constexpr’ expansion of ‘((C*)this)->C::c.B::B(1)’
test.C:2:61: error: modification of ‘*(C*)this’ from outside current evaluation
is not a constant expression
2 | struct B { consteval B () : b (42) {} consteval B (int x) : b (x) {}
int b; };
| ^~~~~