cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2789 [over.match.best.general] Overload resolution with implicit and explicit object member candidates #391

Closed cor3ntin closed 8 months ago

cor3ntin commented 1 year ago

Consider:

template <typename T = int>
struct S {
    constexpr void f(); // #1
    constexpr void f(this S&) requires true; // #2
};

void test() {
    S<> s;
    s.f(); // #3
}

3 is ambiguous because neither overload is a better match, even if #2 is more constrained

This is because constraints are checked only if all the parameter are the same:

In [over.match.best.general]/2.6, we say

F1 and F2 are non-template functions with the same parameter-type-lists, and F1 is more constrained than F2 according to the partial ordering of constraints described in [temp.constr.order]

We probably want to limit to non objects parameters

Proposed resolution

Modify [over.match.best.general]/2.6

F1 and F2 are non-template functions with the same parameter-type-listsnon-object parameters, and F1 is more constrained than F2 according to the partial ordering of constraints described in [[temp.constr.order]], or if not that,(https://eel.is/c++draft/temp.constr.order)

jensmaurer commented 1 year ago

CWG2789