This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-12-19
[Voted into WP at August, 2010 meeting.]
13.7.5 [temp.friend] bullet 1.3 says:
if the name of the friend is a qualified-id and a matching specialization of a function template is found in the specified class or namespace, the friend declaration refers to that function template specialization, otherwise,
I'm not sure this says what it's supposed to say. For example:
namespace N { template<class T> int f(T); } class A { friend int N::f(int); int m; A(); }; namespace N { template< class T > int f(T) { A a; // ok for T=int? return a.m; // ok for T=int? } } int m = N::f(42); // ok? char c = N::f('a'); // Clearly ill-formed.
The key is that the wording talks about a “matching specialization,” which to me means that N::f<int> is befriended only if that specialization existed in N before the friend declaration. So it's ill-formed as written, but if we move the call to N::f<int> up to a point before the definition of A, it's well-formed.
That seems surprising, especially given that the first bullet does not require a pre-existing specialization. So I suggest replacing bullet 3 with something like:
if the name of the friend is a qualified-id and a matching function template is found in the specified class or namespace, the friend declaration refers to the deduced specialization of that function template, otherwise,
Proposed resolution (June, 2010):
Change 13.7.5 [temp.friend] bullet 1.3 as follows:
...For a friend function declaration that is not a template declaration:
...
if the name of the friend is a qualified-id and a matching
specialization of afunction template is found in the specified class or namespace, the friend declaration refers tothat function template specializationthe deduced specialization of that function template (14.8.2.6 [temp.deduct.decl]), otherwise,...
(This resolution depends on that of issue 873; in particular, the cross-reference to 14.8.2.6 [temp.deduct.decl] refers to a new section added by the resolution of that issue.)