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

2024-12-19


2089. Restricting selection of builtin overloaded operators

Section: 12.2.2.3  [over.match.oper]     Status: drafting     Submitter: Hubert Tong     Date: 2015-02-26

The candidates selected by 12.2.2.3 [over.match.oper] include built-in candidates that will result in an error if chosen; this was affirmed by issue 1687. As a result, t+u is ill-formed because it is resolved to the built-in operator+(int*,std::ptrdiff_t), although most implementations do not (yet) agree:

  struct Adaptor { Adaptor(int); };

  struct List { };
  void operator +(List &, Adaptor);

  struct DataType {
    operator int *() const = delete;
    operator List &() const;
  };

  struct Yea;
  struct Nay { int theNaysHaveIt; };

  template <typename T, typename U>
  Yea addCheck(int, T &&t, U &&u, char (*)[sizeof(t + u, 0)] = 0);

  template <typename T, typename U>
  Nay addCheck(void *, T &&t, U &&u);

  void test(DataType &data) { (void)sizeof(addCheck(0, data,
  0.).theNaysHaveIt); }

It might be better to adjust the candidate list in 12.2.2.4 [over.match.ctor] bullet 3.3.3 to allow conversion only on class types and exclude the second standard conversion sequence.