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

2024-10-26


2373. Incorrect handling of static member function templates in partial ordering

Section: 13.7.7.3  [temp.func.order]     Status: CD5     Submitter: Richard Smith     Date: 2018-02-14

[Accepted as a DR at the November, 2018 (San Diego) meeting.]

According to 13.7.7.3 [temp.func.order] paragraph 3,

...If only one of the function templates M is a non-static member of some class A, M is considered to have a new first parameter inserted in its function parameter list. Given cv as the cv-qualifiers of M (if any), the new parameter is of type “rvalue reference to cv A” if the optional ref-qualifier of M is && or if M has no ref-qualifier and the first parameter of the other template has rvalue reference type. Otherwise, the new parameter is of type “lvalue reference to cv A”. [Note: This allows a non-static member to be ordered with respect to a non-member function and for the results to be equivalent to the ordering of two equivalent non-members. —end note]

This gives the wrong answer for an example like:

  struct Foo {
    template <typename T>
    static T* f(Foo*) { return nullptr; }

    template <typename T, typename A1>
    T* f(const A1&) { return nullptr; }
  };

  int main() {
    Foo x;
    x.f<int>(&x);
  }

Presumably this should say something like,

...If only one of the function templates M is a member function, and that function is a non-static member...

Proposed resolution (October, 2018):

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

...If only one of the function templates M is a member function, and that function is a non-static member of some class A, M is considered to have a new first parameter inserted in its function parameter list. Given cv as the cv-qualifiers of M (if any), the new parameter is of type “rvalue reference to cv A” if the optional ref-qualifier of M is && or if M has no ref-qualifier and the first parameter of the other template has rvalue reference type. Otherwise, the new parameter is of type “lvalue reference to cv A”. [Note: This allows a non-static member to be ordered with respect to a non-member function and for the results to be equivalent to the ordering of two equivalent non-members. —end note]