Title
Conversion of std::strong_ordering in a defaulted operator<=>
Status
c++20
Section
11.10.3 [class.spaceship]
Submitter
Richard Smith

Created on 2019-08-14.00:00:00 last changed 7 months ago

Messages

Date: 2019-10-15.00:00:00

Proposed resolution (October, 2019):

Change 11.10.3 [class.spaceship] paragraph 3 as follows:

...If no such index exists, V is static_cast<R>(std::strong_ordering::equal) converted to R.
Date: 2019-11-15.00:00:00

[Adopted as a DR at the November, 2019 meeting.]

According to 11.10.3 [class.spaceship] paragraph 3,

The return value V of type R of the defaulted three-way comparison operator function with parameters x and y of the same type is determined by comparing corresponding elements xi and yi in the expanded lists of subobjects for x and y (in increasing index order) until the first index i where the synthesized three-way comparison for comparison category type R between xi and yi yields a result value vi where vi != 0, contextually converted to bool, yields true; V is vi converted to R. If no such index exists, V is std::strong_ordering::equal converted to R.

This is meaningless, however, because the kind of conversion is not specified. According to bullet 1.1,

  • If overload resolution for a <=> b finds a usable function (12.2 [over.match]), static_cast<R>(a <=> b).

so consistency would suggest that static_cast<R>(std::strong_ordering::equal) is probably the right answer.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6470
2019-08-14 00:00:00admincreate