https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113830
Bug ID: 113830 Summary: GCC accepts invalid code when instantiating the local class inside a function Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wangbopku15 at gmail dot com Target Milestone: --- The following invalid code is accepted by both x86-64 gcc-trunk and x86-64 gcc-13.2: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template<typename T> void f() { struct S { void g(int n = T::unknown){}; }; } template void f<int>(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The code is invalid because the type name "int" passed in the template function specialization does not contain the member "unknown": It appears that if a template function has an internally defined local class that uses a dependent name in its member function, it can cause the compiler's name-binding process to get into trouble. If we compile it via clang-trunk, it rejects the code with the error message: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:2:29: error: type 'int' cannot be used prior to '::' because it has no members ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please see the godbolt to reproduce it: https://godbolt.org/z/nb3rE8s5a