Title
Taking the address of a function involving template argument deduction
Status
open
Section
12.3 [over.over]
Submitter
Anoop Rana

Created on 2024-03-16.00:00:00 last changed 9 months ago

Messages

Date: 2024-03-18.19:37:42

(From submission #516.)

Consider:

  template <typename T>
  int f(T&&);

  void g();                      // #1

  template <typename T>
  void g();                      // #2

  int x = f(&g);

All major implementations reject. However, 12.3 [over.over] paragraph 3 seems to say that templates are ignored if template argument deduction fails ("if any"):

The specialization, if any, generated by template argument deduction (13.10.4 [temp.over], 13.10.3.3 [temp.deduct.funcaddr], 13.10.2 [temp.arg.explicit]) for each function template named is added to the set of selected functions considered.

For the following example, prior core issues 2608 and 2848 have indicated that "deduction" should always consider default template arguments. Yet, only gcc accepts the example.

  template<typename T> int f(T);
  template<typename T = int> void g();
  int x = f(&g);

See also issue 2572.

Subclause 13.10.3.6 [temp.deduct.type] bullet 5.6.3 makes the parameter of f a non-deduced context for these situations. However, 13.10.2 [temp.arg.explicit] paragraph 4 allows omitting the template argument list if all template parameters can be deduced or obtained from default template arguments. Thus, &g can be considered to refer to both a function template and a function template specialization.

The special treatment in overload resolution for f yields inconsistent outcomes where overload resolution is not applied:

  void g(int);
  void g(auto);

  decltype(&g) p;    // rejected by implementations for no reason in the wording
History
Date User Action Args
2024-03-16 00:00:00admincreate