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

2024-04-28


2802. Constrained auto and redeclaration with non-abbreviated syntax

Section: 9.3.4.6  [dcl.fct]     Status: open     Submitter: Richard Smith     Date: 2023-09-26

Consider:

  template<typename T> void f(T);
  void f(auto);

These are redeclarations according to 9.3.4.6 [dcl.fct] paragraph 22:

... An abbreviated function template is equivalent to a function template (13.7.7 [temp.fct]) whose template-parameter-list includes one invented type template-parameter for each generic parameter type placeholder of the function declaration, in order of appearance. ...

The same applies to constrained abbreviated functions:

  template<C T> void g(T);
  void g(C auto);          // redeclaration

However, this leads to a situation where two function templates are equivalent, but not functionally equivalent:

  template<typename T> requires D<T> void h(C auto); // #1
  template<typename T, C U> requires D<T> void h(U); // #2

According to 13.5.3 [temp.constr.decl] bullet 3.3, #1 has the associated constraints D<T> && C<auto_param_1> whereas #2 has the associated constraints C<U> && D<T> (note reverse order). Those are observably different because satisfaction is checked in lexical order and instantiation of one of the associated constraints may yield an error not in the immediate context.

A number of options are available: