The first problem (I think) is from & sect; 9.3 / 7 [class.mfct] and possibly some other places in the standard (see clang post and answer 101010 below):
Previously declared member functions may be referred to in friend announcements.
This problem is similar to that of this question .
Since you did not declare A<T>::f before C , you cannot declare that it has a friend C
But there is a hidden problem executing the clang message , if you create an A not templated class, the message is different:
Incomplete type A in a nested name specifier.
Which is closer to the gcc message than to the actual one, is because the clang warning is something else. Per & sect; 14.5.4 / 5 [temp.friend] , the standard allows a class template member to be a friend, so this should be valid:
template <typename T> struct A { void f (); }; class C { template <typename T> friend void A<T>::f();
But clang still complains:
warning: the dependent qualifier nested name 'A ::' for declaring a friend's class is not supported; disabling access control for "C" [-Wunsupported-friend]
clang does not support this friend declaration, so it just disables access control for C , which means:
C c; c.private_member();
It will be "valid" everywhere that may not be what you want.
Holt
source share