[clang-tools-extra] [clang-tidy] Apply DeMorgan to overloaded operator in the 'readability-simplify-boolean-expr' check (PR #164141)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 19 19:57:02 PDT 2025


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


More information about the cfe-commits mailing list