-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
This program compiles with clang 19.1.2 but fails to compile with MSVC 19.41:
#include <compare>
class C
{
double d1;
double d2;
std::strong_ordering operator<=>(const C&) const = default;
};
int main()
{
return 0;
}The MSVC error message:
main.cpp(7): error C7549: 'C::operator <=>':
defaulted comparison function cannot be declared to return a comparison
category stronger than the common category among bases and members which was deduced to be 'std::partial_ordering'
In my opinion MSVC is correct because double by default only supports std::partial_ordering because of NaN values.
See also here: https://en.cppreference.com/w/cpp/utility/compare/partial_ordering
The built-in operator<=>between floating-point values uses this ordering:
the positive zero and the negative zero compare equivalent, but can be
distinguished, and NaN values compare unordered with any other value.
Why does clang compile the code?