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


2834. Partial ordering and explicit object parameters

Section: 13.7.7.3  [temp.func.order]     Status: review     Submitter: Jason Merrill     Date: 2023-12-02

Consider:

  template <typename T>
  struct A {
    T f(this auto, auto);   // #1
    int f(auto);            // #2
  };
  int main() {
    A<int>().f(42);
  }

There is implementation divergence in the handling of this example: Clang and MSVC consider the example ambiguous, EDG chooses #1.

Proposed resolution (reviewed by CWG 2024-01-19):

Change in 13.7.7.3 [temp.func.order] paragraph 3 as follows:

Each function template M that is a member function with no explicit object parameter is considered to have a new first parameter of type X(M), described below, inserted in its function parameter list. If exactly one of the function templates was considered by overload resolution via a rewritten candidate (12.2.2.3 [over.match.oper]) with a reversed order of parameters, then the order of the function parameters in its transformed template is reversed. For a function template M with cv-qualifiers cv that is a non-static member of a class A: For a function template M that is a static member of a class A: [Note 2: This allows a non-static member to be ordered with respect to a static or non-member function and for the results to be equivalent to the ordering of two equivalent non-members. —end note]

CWG 2024-01-19

It seems #2 should be chosen, because it is more specialized than #1.