https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115676
Bug ID: 115676 Summary: gcc allows invalid calling to implicitly-deleted default constructor of a template derived class in template function 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: --- The following invalid code is accepted by gcc-13.2.0 and gcc-trunk: ~~~~~~~~~~~~~~~~~~~~~~ struct empty{ }; template <int size> struct A : public empty { const int is_valid; }; template <class T> void check_a() { const A<0> a {}; } ~~~~~~~~~~~~~~~~~~~~~~ It can be seen that the template class "A" is non-trivial because it has an empty base class. Thus, the default constructor of "A" should be implicitly deleted, and the initialization statement "const A<0> a{}" should be invalid. But when the initialization happens in a template function, GCC seems to ignore the error. Changing "check_a" to a non-template function can make the compiler reject the code by giving the following error message: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>: In function 'void check_a()': <source>:14:17: error: use of deleted function 'A<0>::A()' 14 | const A<0> a {}; | ^ <source>:5:8: note: 'A<0>::A()' is implicitly deleted because the default definition would be ill-formed: 5 | struct A | ^ <source>: At global scope: <source>:5:8: error: uninitialized const member in 'struct A<0>' <source>:8:15: note: 'const int A<0>::is_valid' should be initialized 8 | const int is_valid; | ^~~~~~~~ <source>: In function 'void check_a()': <source>:14:17: note: use '-fdiagnostics-all-candidates' to display considered candidates 14 | const A<0> a {}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please check https://godbolt.org/z/nGxPdn9jf