https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115715
Bug ID: 115715 Summary: gcc seems to incorrectly accept illegal constexpr constructor in virtual inheritance and static template class member Product: gcc Version: 13.2.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rush102333 at gmail dot com Target Milestone: --- We have encountered unexpected compiler output by compiling the following code with gcc-13.2: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct Storage { constexpr Storage(int) {} }; struct Derived :virtual Storage { using Storage::Storage; }; template<typename> struct Template { static constexpr Derived kDerived{0}; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The compiler normally accepts the code without providing any error message. But to our knowledge, constructors of classes having virtual bases are not allowed to be declared as constexpr, even if the constructor of the base class is declared constexpr. https://godbolt.org/z/exjb3v9MW Additionally, changing the class "Template" to a non-template class makes GCC correctly reject the code by reporting the following error: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:11:40: error: 'constexpr Derived::Derived(int) [inherited from Storage]' called in a constant expression 11 | static constexpr Derived kDerived{0}; | ^ <source>:6:20: note: 'constexpr Derived::Derived(int) [inherited from Storage]' is not usable as a 'constexpr' function because: 6 | using Storage::Storage; | ^~~~~~~ <source>:6:20: error: 'struct Derived' has virtual base classes Compiler returned: 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ https://godbolt.org/z/Gx5Gjxzn4 Clang always rejects the code no matter whether "Template" is actually a template class or not by giving error messages similar to that provided by GCC above. We think that should probably be a bug of GCC and need to be taken a look at.