[clang] [clang][Sema] Warn consecutive builtin comparisons in an expression (PR #92200)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed May 15 10:13:52 PDT 2024
================
@@ -215,3 +215,10 @@ namespace PR20735 {
// fix-it:"{{.*}}":{[[@LINE-9]]:20-[[@LINE-9]]:20}:")"
}
}
+
+void consecutive_builtin_compare(int x, int y, int z) {
+ (void)(x < y < z); // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
+ (void)(x < y > z); // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
+ (void)(x < y <= z); // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
+ (void)(x <= y > z); // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
----------------
AaronBallman wrote:
I'd like an additional test along the lines of:
```
(void)((x < y) >= z);
```
and what about something along these lines?
```
struct S {
bool operator<(const S &) const;
} s, t;
(void)(s < t >= z);
```
perhaps that should diagnose while this should not?
```
struct S {
S operator<(const S &) const;
} a, b;
struct T {
friend bool operator>=(const S &, const T &);
} c;
bool val = (a < b >= c);
```
https://github.com/llvm/llvm-project/pull/92200
More information about the cfe-commits
mailing list