[clang] [clang][Sema] Warn consecutive builtin comparisons in an expression (PR #92200)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri May 17 06:31:14 PDT 2024


================
@@ -85,7 +85,7 @@ void f(int x, int y, int z) {
   if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}}
 
   if ((a<y) == z) {} // no warning
-  if (a>y<z)      {} // no warning
+  if (a>y<z)      {} // expected-warning {{comparisons like 'X<=Y<=Z' don't have their mathematical meaning}}
----------------
erichkeane wrote:

I realize this is GCC's diagnostic, but I think it isn't particularly good of a diag.  I would prefer we:

1- At least match operators.  I REALLY wish we could print the actual expression (unless the expression complicated, at which point we print `<expr>` or something).  So something like: `comparison 'a>y<z' does not have its mathematical meaning`.

2- I REALLY wish we had a note after it with the range of the LHS here that says something like `Left comparison operator evaluates to `bool` before 'less-than' comparison with 'z'`.

https://github.com/llvm/llvm-project/pull/92200


More information about the cfe-commits mailing list