This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


1056. Template aliases, member definitions, and the current instantiation

Section: 13.7.8  [temp.alias]     Status: C++11     Submitter: John Spicer     Date: 2010-03-17

[Voted into the WP at the March, 2011 meeting as part of paper N3262.]

According to 13.8.3.2 [temp.dep.type] paragraph 1, in a primary class template a name refers to the current instantiation if it is the injected-class-name or the name of the class template followed by the template argument list of the template. Although a template-id referring to a specialization of a template alias is described as “equivalent to” the associated type, a specialization of a template alias is neither of the things that qualifies as naming the current instantiation, so presumably the typename keyword in the following example is required:

    template <class T> struct A;
    template <class T> using B = A<T>;

    template <class T> struct A {
        struct C {};
        typename B<T>::C bc;  // typename needed
    };

(However, the list in 13.8.3.2 [temp.dep.type] may not be exactly what we want; it doesn't allow use of a typedef denoting the type of the current instantiation, either, but that presumably should be accepted.)

For analogous reasons, it should not be permitted to use a template alias as a nested-name-specifier when defining the members of a class template:

    template <class T> struct A {
        void g();
    };
    template <class T> using B = A<T>;
    template <class T> void B<T>::g() {} // error

Notes from the November, 2010 meeting:

The CWG disagreed with the suggested direction, feeling that aliases should work like typedefs and that the examples should be accepted.

Proposed resolution (November, 2010) [SUPERSEDED]:

  1. Change 13.8.3.2 [temp.dep.type] paragraph 1 as follows:

  2. In the definition of a class template, a nested class of a class template, a member of a class template, or a member of a nested class of a class template, a name refers to the current instantiation if it is

    Change 13.8.3.2 [temp.dep.type] paragraph 3 as follows:

    A template argument that is equivalent to a template parameter (i.e., has the same constant value or the same type as the template parameter) can be used in place of that template parameter in a reference to the current instantiation, except that a decltype-specifier that denotes a dependent type is always considered non-equivalent. In the case of a non-type template argument, the argument must have been given the value of the template parameter and not an expression in which the template parameter appears as a subexpression. [Example:...

This resolution also resolves issue 1057.