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

2024-10-26


2447. Unintended description of abbreviated function templates

Section: 9.2.9.7  [dcl.spec.auto]     Status: C++20     Submitter: Hubert Tong     Date: 2019-10-15

[Accepted at the February, 2020 (Prague) meeting.]

The current wording for abbreviated function templates could lead to the incorrect conclusion that f and g in the example below are well-formed abbreviated function templates. The g case is the abbreviated function template analog of issue 2053 regarding generic lambdas.

9.2.9.7 [dcl.spec.auto] paragraph 4 clearly disallows the ap case. The inconsistency between the paragraph 2 wording for abbreviated function templates and the paragraph 4 wording is unintentional.

  template <typename> struct A;
  void f(A<auto> x);
  void g(auto f() -> int);
  A<auto> *ap = static_cast<A<int> *>(0);

Proposed resolution (February, 2020):

  1. Change 9.2.9.7 [dcl.spec.auto] paragraph 2 as follows:

  2. A placeholder-type-specifier of the form type-constraintopt auto can be used in as a decl-specifier of the decl-specifier-seq of a parameter-declaration of a function declaration or lambda-expression and, if it is not the auto type-specifier introducing a trailing-return-type (see below), is a generic parameter type placeholder of the function declaration or lambda-expression. [Note: Having a generic parameter type placeholder signifies that the function is an abbreviated function template (9.3.4.6 [dcl.fct]) or the lambda is a generic lambda (7.5.6 [expr.prim.lambda]). end note]
  3. Change 9.3.4.6 [dcl.fct] paragraph 18 as follows:

  4. An abbreviated function template is a function declaration whose parameter-type-list includes that has one or more generic parameter type placeholders (9.2.9.7 [dcl.spec.auto]). An abbreviated function template is equivalent to a function template (13.7.7.2 [temp.over.link]) whose template-parameter-list includes one invented type template-parameter for each occurrence of a generic parameter type placeholder type in the decl-specifier-seq of a parameter-declaration in the function's parameter-type-list of the function declaration, in order of appearance. For a placeholder-type-specifier of the form...
  5. Change 7.5.6 [expr.prim.lambda] paragraph 5 as follows:

  6. A lambda is a generic lambda if there is a decl-specifier that is a placeholder-type-specifier in the decl-specifier-seq of a parameter-declaration of the lambda-expression has any generic parameter type placeholders (9.2.9.7 [dcl.spec.auto]), or if the lambda has a template-parameter-list. [Example:...

This resolution also resolves issue 2053.