Skip to content

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

@cor3ntin

Description

@cor3ntin

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions