http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52065
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-31 12:55:53 UTC --- template <typename T2> friend void f(A<T>, T2); would be a partial specialization of f which is not allowed. I don't think it is possible to do what you are trying to do.