Title
Recursive instantiation via alias template
Status
c++11
Section
13.7.8 [temp.alias]
Submitter
US

Created on 2010-08-03.00:00:00 last changed 96 months ago

Messages

Date: 2010-11-15.00:00:00

[Voted into the WP at the November, 2010 meeting.]

Date: 2010-08-15.00:00:00

Proposed resolution (August, 2010):

Add the following as a new paragraph at the end of 13.7.8 [temp.alias]:

The type-id in an alias template declaration shall not refer to the alias template being declared. The type produced by an alias template specialization shall not directly or indirectly make use of that specialization. [Example:

  template <class T> struct A;
  template <class T> using B = typename A<T>::U;
  template <class T> struct A {
    typedef B<T> U;
  };
  B<short> b; // Error: instantiation of B<short> uses own type via A<short>::U.

end example]

[Note: this wording assumes the change from “template alias” to “alias template” requested by comment FI 11 on FCD N3092.]
Date: 2010-08-03.00:00:00
N3092 comment US 73

The current wording of 9.2.4 [dcl.typedef] paragraph 2 requires that the identifier in an alias-declaration “...shall not appear in the type-id.” With template aliases, however, the name of the alias can be used indirectly:

    template<typename T> struct A;
    template<typename T> using B=typename A<T>::U;
    template<typename T> struct A {
      typedef B<T> U;
    };
    B<short> b;

Here the instantiation of B<short> causes the instantiation of A<short>, and the typedef in A<short> ends up attempting to use B<short>, which is still in the process of being instantiated.

There should be an explicit prohibition of such uses.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetstatus: dr -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3201
2010-11-29 00:00:00adminsetstatus: ready -> dr
2010-08-23 00:00:00adminsetmessages: + msg2807
2010-08-03 00:00:00admincreate