Issue 115182
Summary clang 19 raises operator<=>() return type to std::strong_ordering for double
Labels
Assignees
Reporter pkl97
    This program compiles with clang 19.1.2 but fails to compile with MSVC 19.41:

```c++
#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?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to