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


585. Friend template template parameters

Section: 11.8.4  [class.friend]     Status: NAD     Submitter: James Widman     Date: 15 June 2006

After the adoption of the wording for extended friend declarations, we now have this new paragraph in 11.8.4 [class.friend]:

A friend declaration that does not declare a function shall have one of the following forms:

But what about friend class templates? Should the following examples compile in C++0x?

    template< template <class> class T >
         struct A{ friend T; };

    template< class > struct C;
    struct B{ friend C; };

Proposed resolution (June, 2008):

Change 11.8.4 [class.friend] paragraph 3 as follows:

A friend declaration that does not declare a function shall have one of the following forms:

In the last alternative, the identifier shall name a template template-parameter. [Note: a friend declaration may be the declaration in a template-declaration (Clause 13 [temp], 13.7.5 [temp.friend]). —end note] If the type specifier in a friend declaration designates a (possibly cv-qualified) class type or a class template, that class or template is declared as a friend; otherwise, the friend declaration is ignored. [Example:...

Rationale (September, 2008):

The proposed extension is not needed. The template case can be handled simply by providing a template header:

    template <typename T> friend class X<T>;