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

2025-03-10


3003. Naming a deducible template for class template argument deduction

Section: 9.2.9.3  [dcl.type.simple]     Status: open     Submitter: Hubert Tong     Date: 2025-02-02

(From submission #670.)

Consider:

  template <template <typename> class TT>
  void f() { TT x(42); }  // #1

  template <typename T> struct A { A(T); };

  void g() { f<A>(); }

Using a template template parameter should not enable class template argument deduction at #1. However, while the normative rules are clear, all implementations accept the code above, but fail (sometimes spectacularly) when parsing situations involving alias templates:

  template <typename T> struct A { A(T); };

  template <typename T, template <typename> class TT = A>
  using Alias = TT<T>;

  template <typename T>
  using Alias2 = Alias<T>;

  void h() { Alias2 a(42); }
  void h2() { Alias a(42); }

Possible resolution:

Change in 9.2.9.3 [dcl.type.simple] paragraph 3 and add numbered paragraphs as follows:

(3) A placeholder-type-specifier is a placeholder for a type to be deduced (9.2.9.7 [dcl.spec.auto]).

(4) A type-specifier of the form

typename/opt nested-name-specifier/opt template-name
is a placeholder for a deduced class type (9.2.9.8 [dcl.type.class.deduct]). The nested-name-specifier, if any, shall be non-dependent and the template-name shall name a deducible template. A deducible template is either a class template or is an alias template whose defining-type-id is of the form typenameopt nested-name-specifieropt templateopt simple-template-id where the nested-name-specifier (if any) is non-dependent and the template-name of the simple-template-id names a deducible template. [Note: A template template parameter (13.2 [temp.param]) does not name a deducible template. -- end note] [Note: An injected-class-name is never interpreted as a template-name in contexts where class template argument deduction would be performed (13.8.2 [temp.local]). —end note]

(5) The other simple-type-specifiers specify either a previously-declared type, a type determined from an expression, or one of the fundamental types (6.8.2 [basic.fundamental]).

(6)Table 17 summarizes the valid combinations of simple-type-specifier s and the types they specify.