https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77812
--- Comment #3 from Nathan Sidwell <nathan at gcc dot gnu.org> --- The struct variant only 'works' because 'struct X' is a valid incomplete struct declaration. Try: struct f {}; template <typename> void f () { struct f Q; } template void f<int> (); void f() void f() [with <template-parameter-1-1> = int] ../../../77812-struct.ii: In instantiation of 'void f() [with <template-parameter-1-1> = int]': ../../../77812-struct.ii:9:23: required from here ../../../77812-struct.ii:6:12: error: 'f() [with <template-parameter-1-1> = int]::f Q' has incomplete type struct f Q; ^