https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71679
--- Comment #1 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- The testcase can be further reduced: template <int> struct A; struct B { template <int, int> friend struct ::A; }; When using A instead of ::A it works fine and gcc errors out: llvm.ii:3:37: error: redeclared with 2 template parameters template <int, int> friend struct A; ^ llvm.ii:1:23: note: previous declaration ‘template<int <anonymous> > struct A’ used 1 template parameter template <int> struct A; ^