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


2332. template-name as simple-type-name vs injected-class-name

Section: 9.2.9.3  [dcl.type.simple]     Status: CD5     Submitter: Daveed Vandevoorde     Date: 2016-12-10

[Accepted as a DR at the February, 2019 meeting.]

Paper P0091R3 has the following example:

  template<typename T> struct X {
    template<typename Iter>
    X(Iter b, Iter e) { /* ... */ }

    template<typename Iter>
    auto foo(Iter b, Iter e) {
      return X(b, e); // X<U> to avoid breaking change
    }

    template<typename Iter>
    auto bar(Iter b, Iter e) {
      return X<Iter::value_type>(b, e); // Must specify what we want
    }
  };

The intent was presumably to avoid breaking existing code, but the new wording in 9.2.9.3 [dcl.type.simple] paragraph 2 appears to make the expression X(b, e) ill-formed:

A type-specifier of the form typenameopt nested-name-specifieropt template-name is a placeholder for a deduced class type (9.2.9.8 [dcl.type.class.deduct]). The template-name shall name a class template that is not an injected-class-name.

Suggested resolution:

Deleting the wording in question and replacing it with a cross-reference to 13.8.2 [temp.local], which makes it clear that the injected-class-name is a type-name and not a template-name in this context, would seem to address the problem adequately.

Proposed resolution (November, 2018):

Change 9.2.9.3 [dcl.type.simple] paragraph 2 as follows:

The simple-type-specifier auto is a placeholder for a type to be deduced (9.2.9.7 [dcl.spec.auto]). A type-specifier of the form typenameopt nested-name-specifieropt template-name is a placeholder for a deduced class type (9.2.9.8 [dcl.type.class.deduct]). The template-name shall name a class template that is not an injected-class-name. [Note: An injected-class-name is never interpreted as a template-name in contexts where a type-specifier may appear (13.8.2 [temp.local]). —end note] The other simple-type-specifiers specify...