This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See for the official list.


674. “matching specialization” for a friend declaration

Section: 13.7.5  [temp.friend]     Status: C++11     Submitter: James Widman     Date: 7 February, 2008

[Voted into WP at August, 2010 meeting.]

13.7.5 [temp.friend] bullet 1.3 says:

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;

    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:

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:

(This resolution depends on that of issue 873; in particular, the cross-reference to [temp.deduct.decl] refers to a new section added by the resolution of that issue.)