https://github.com/HerrCai0907 commented:

That is not true, when then overloaded operation provide the partial order 
sema, when the check will cause the wrong result.
e.g.
```c++
#include <compare>
#include <iostream>

struct A {
  int v;
  bool isValid;
  std::partial_ordering operator<=>(const A &other) const {
    if (!isValid || !other.isValid) {
      return std::partial_ordering::unordered;
    }
    if (v < other.v) {
      return std::partial_ordering::less;
    } else if (v > other.v) {
      return std::partial_ordering::greater;
    } else {
      return std::partial_ordering::equivalent;
    }
  }
};

int main() {
  A a{5, true};
  A b{0, false};

  std::cout << "a > b: " << (a > b) << std::endl;
  std::cout << "a <= b: " << (a <= b) << std::endl;
  return 0;
}
```
The result will be 
```
a > b: 0
a <= b: 0
```


https://github.com/llvm/llvm-project/pull/164141
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to