A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/cplusplus/draft/issues/5335 below:

[class.compare.secondary] The extent to which "The defaulted operator function is not considered" applies CWG2546 · Issue #5335 · cplusplus/draft · GitHub

[class.compare.secondary] p2

The operator function with parameters x and y is defined as deleted if

Otherwise, the operator function yields x @ y. The defaulted operator function is not considered as a candidate in the overload resolution for the @ operator.

Consider this example

struct C{
    friend int operator <=>(C const&, C const&){
        return -1;
    }
    bool operator <(C const&) const = default;
};
int main(){
    C x,y;
    bool r = x<y;  // #1
}

The actual call at #1 is C::operator<(C const&) const, which is exposed by GCC and Clang. That is, they do consider the defaulted operator function as a candidate in the overload resolution for operator <. Presumably, the emphasized wording is defined for the first bullet. Is it more clear to move the wording into the point after the first bullet?

overload resolution ([over.match]), as applied to x @ y, does not result in a usable candidate; The defaulted operator function is not considered as a candidate in the overload resolution for the @ operator.

Another wording that is hard to read:

Otherwise, the operator function yields x @ y

What does "the operator function yields x @ y" mean? GCC and Clang expose that the definition for the defaulted operator< function uses the call to operator<=>(C const&, C const&). However, this behavior cannot be read from this wording. Presumably, the wording may mean that

The implicitly-defined default operator function performs that the expression x@y is interpreted according to the usable candidate selected as above, as defined in [over.match.oper].

Such as the above example, since operator <=> is a usable candidate, according to [over.match.oper], x<y is interpreted as (x <=> y) @ 0, the effect of the defaulted operator < will behave the same as that of (x <=> y) @ 0.

The improvement to [class.compare.secondary] p2

The operator function with parameters x and y is defined as deleted if

Otherwise, the implicitly-defined default operator function performs the same as that the expression x@y is interpreted according to the usable candidate, as defined in [over.match.oper].

For the purpose of this definition, the defaulted operator function is not considered as a candidate in the overload resolution for the @ operator.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4