http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-08 15:08:36 UTC --- (In reply to comment #4) > (In reply to comment #2) > > This code is not valid, G++ is correct to reject it. > > Please explain why the code is invalid, and do not click "Resolved invalid" > until ClassB is a friend of ClassA. You reported an invalid bug, so I rejected it. It's not my job to teach you C++ but here you go: template <class T, int C> class A; template <class T, int C, A<T,C> &a> class B; template <class T, int C> class A { template <class X, int Y, A<X,Y>&> friend class B; }; That makes B<X,Y,A<X,Y>&> a friend of A Your original example is invalid for the reason the compiler gave, the syntax you tried to use declares a partial specialization, which is not allowed in a friend declaration. That's how C++ works, I don't make the rules.