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

2024-03-20


1158. Recursive instantiation via alias template

Section: 13.7.8  [temp.alias]     Status: C++11     Submitter: US     Date: 2010-08-03

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

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.

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.]