https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120506
Bug ID: 120506 Summary: [16 Regression] Missing reason for failed constinit since r16-57 Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org CC: jason at gcc dot gnu.org Target Milestone: --- Given this code to be compiled with -std=c++20: struct A { constexpr A(int c) : counter(c) { } int counter; }; struct B : A { constexpr B(int c) : A(c) { } int i; // OOPS, not initialized }; struct C { B sem; constexpr C(int c) : sem(c) { } }; constinit C s(0); GCC 15 explains the problem: sem.cc:23:13: error: 'constinit' variable 's' does not have a constant initializer 23 | constinit C s(0); | ^ sem.cc:23:16: error: 'C{B{A{0}}}' is not a constant expression 23 | constinit C s(0); | ^ sem.cc:23:16: error: 's.C::C(0)' is not a constant expression because it refers to an incompletely initialized variable Since r16-57-g9ac98b5742ebce we're missing the last error: sem.cc:23:13: error: 'constinit' variable 's' does not have a constant initializer 23 | constinit C s(0); | ^ sem.cc:23:16: error: 'C{B{A{0}}}' is not a constant expression 23 | constinit C s(0); | ^ I refactored the class B to move the member into a base class A, but forgot to remove the B::i member, and the error was not at all helpful in understanding why I couldn't use a constinit variable! r16-57 was: c++: reorder constexpr checks My proposed change to stop setting TREE_STATIC on constexpr heap pseudo-variables led to a diagnostic regression because we would get the generic "not constant" diagnostic before the "allocated storage" diagnostic. So let's move the generic verify_constant down a bit. gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_outermost_constant_expr): Move verify_constant later.