Issue 129098
Summary [clang-tidy] Check request: improve greater equals or less equals operators
Labels clang-tidy
Assignees
Reporter denzor200
    
Needs a check that will find a definition of `operator>=` or `operator<=` which performs more than 1 invocations of another compare operators. The check will suggest to change the logic using only 1 invocation, and the observable behavior will remains unchanged.

BEFORE
```
bool operator>=(const A& lhs, const A& rhs) { return (rhs < lhs) || (lhs == rhs); }
bool operator<=(const A& lhs, const A& rhs) { return (lhs < rhs) || (lhs == rhs); }

bool operator>=(const B& lhs, const B& rhs) { return (lhs > rhs) || (lhs == rhs); }
bool operator<=(const B& lhs, const B& rhs) { return (rhs > lhs) || (lhs == rhs); }
```

AFTER
```
bool operator>=(const A& lhs, const A& rhs) { return !(lhs < rhs); }
bool operator<=(const A& lhs, const A& rhs) { return !(rhs < lhs); }

bool operator>=(const B& lhs, const B& rhs) { return !(rhs > lhs); }
bool operator<=(const B& lhs, const B& rhs) { return !(lhs > rhs); }
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to