A RetroSearch Logo

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

Search Query:

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

[class.compare.default] p1 The condition of implicitly defining a defaulted comparison operator function CWG2546 · Issue #5336 · cplusplus/draft · GitHub

[class.compare.default] p1 just says

A comparison operator function for class C that is defaulted on its first declaration and is not defined as deleted is implicitly defined when it is odr-used or needed for constant evaluation.

Consider this example

struct HasNoLessThan { };
struct C{
    friend HasNoLessThan operator <=>(C const&, C const&);
    bool operator <(C const&) const /*noexcept*/ = default;
};
int main(){
   using ptr = decltype(&C::operator<); // #1
}

Since &C::operator< appears as an unevaluated operand, function C::operator < is not odr-used by this expression. However, Clang reports a diagnosis that:

in evaluation of exception specification for 'C::operator<' needed here

[except.spec] p11 says

The exception specification for a comparison operator function ([over.binary]) without a noexcept-specifier that is defaulted on its first declaration is potentially-throwing if and only if any expression in the implicit definition is potentially-throwing.

So, It is reasonable to check the definition of the defaulted function. However, we just define two contexts that can cause the implicit definition for the defaulted function. Checking the expressions in the implicit definition is not defined to be odr-used nor constant evaluation of the function. It seems that we lack the case that determines the exception specification of a defaulted comparison operator function.

Improvement:

A comparison operator function for class C that is defaulted on its first declaration and is not defined as deleted is implicitly defined when it is odr-used, needed for constant evaluation, or needed to determine exception specification(if necessary).


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