https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890
Bug ID: 106890 Summary: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: thomas at thomaslabs dot org Target Milestone: --- Created attachment 53549 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53549&action=edit The exact source code used to trigger the error The following code sample triggers an internal compiler error. This happends when using the virtual keyword in the definition of B and is related to the function call to f inside the class definition. When later attempting to instantiate the class B the compiler fails. I'm working with GCC version 12.2.0 but this bug seems to be present as early as version 8.5.0. Version 7.5.0 managed to compile without a problem. * Command line g++ bug.cpp * Compiler output: during RTL pass: expand bug.cpp: In constructor ‘B<T>::B(int) [with T = int]’: bug.cpp:26:5: internal compiler error: in expand_expr_real_1, at expr.cc:10586 26 | B(int a) { | ^ 0x1b286a6 internal_error(char const*, ...) ???:0 0x6ccc1e fancy_abort(char const*, int, char const*) ???:0 * Compiler version: GNU C++17 (GCC) version 12.2.0 (x86_64-unknown-linux-gnu) compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.23-GMP * System GNU/Guix x86_64 * Source code class O { public: int f() { return 1; } }; template<typename T> class A { public: A(); A(int a); protected: O p = O(); }; template<typename T> class B : virtual public A<T> { public: B() { } B(int a) { } protected: using A<T>::p; unsigned int k = p.f(); }; template class B<int>; int main() { return 0; }