https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97128
Bug ID: 97128 Summary: Uninitialized members of base class wrongly allowed in constexpr constructor Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: feodor.alexeev+gcc at gmail dot com Target Milestone: --- Given this code: (https://godbolt.org/z/qsaeM7) struct Base { int x; }; struct Derived : Base { constexpr Derived() { } }; int main () { constexpr Derived kDerived; return kDerived.x; } g++ -std=c++17 -pedantic compiles the program that exits with code 0. clang rejects it as I believe in c++17 for a constructor to be constexpr all members must be initialized before execution enters the body of the constructor. I also believe that the program is invalid as of c++20 as all must be initialized by the end of the constexpr constructor. Still g++ -std=c++2a compiles it. Note that if there was an uninitialized member of Derived itself, g++ would generate an error as expected. There is a similar bug filed where g++ wrongly allows uninitialized member of anonymous struct inside a union member: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86581 . Not sure if this counts as a duplicate.