http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942
--- Comment #15 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-09 18:18:56 UTC --- you don't even need the partial specialization of Befriender: template<class, int> class A; template<class T, int C, A<T,C>&> class A; template<class T, int C> struct Befriender { typedef B<T,C,A<T,C>&> type; }; template<class T, int C> class A { friend typename Befriender<T,C,A>::type; }; (I can't test this now, so it might be wrong, and it definitely isn't allowed in C++03)