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

2023-02-07


2052. Template argument deduction vs overloaded operators

Section: 12.4  [over.oper]     Status: CD4     Submitter: Richard Smith     Date: 2014-12-03

[Moved to DR at the October, 2015 meeting.]

In an example like

  struct A { operator int(); };
  template<typename T> T operator<<(T, int);
  void f(A a) { 1 << a; }

Template argument deduction succeeds for the operator template, producing the signature operator<<(int,int). The resulting declaration is synthesized and added to the overload set, per 13.10.4 [temp.over] paragraph 1. However, this violates the requirement of 12.4 [over.oper] paragraph 6,

An operator function shall either be a non-static member function or be a non-member function that has at least one parameter whose type is a class, a reference to a class, an enumeration, or a reference to an enumeration.

This is not a SFINAE context, so the program is ill-formed, rather than selecting the built-in operator.

Proposed resolution (May, 2015):

Change 13.10.4 [temp.over] paragraph 1 as follows,

...If, for a given function template, argument deduction fails or the synthesized function template specialization would be ill-formed, no such function is added to the set of candidate functions for that template.