CWG Issue 2789 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118f. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-11-07
2789. Overload resolution with implicit and explicit object member functions
Section: 12.2.4.1 [over.match.best.general]Status: CD7Submitter: Corentin JabotDate: 2023-08-08
[Accepted as a DR at the November, 2023 meeting.]
Consider:
template struct S { constexpr void f(); // #1 constexpr void f(this S&) requires true; // #2 };
void test() { S<> s; s.f(); // #3 }
With the current rules, the call at #3 is ambiguous, even though #2 is more constrainted.
Proposed resolution (approved by CWG 2023-11-07):
Change in 12.2.4.1 [over.match.best.general] bullet 2.6 as follows:
- ...
- F1 and F2 are non-template functions
withand
- they have the same
parameter-type-listsnon-object-parameter-type-lists (9.3.4.6 [dcl.fct]), and- if they are member functions, both are direct members of the same class, and
- if both are non-static member functions, they have the same types for their object parameters, and
- F1 is more constrained than F2 according to the partial ordering of constraints described in 13.5.5 [temp.constr.order],
or if not that,
[ Example:
template
struct S {
constexpr void f(); // #1
constexpr void f(this S&) requires true; // #2
};
void test() {
S<> s;
s.f(); // calls #2
}
-- end example ]- ...