[clang] [Clang] Warning as error for fold expressions over comparison operators (PR #136836)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 23 04:58:28 PDT 2025


================
@@ -7138,6 +7138,13 @@ def warn_consecutive_comparison : Warning<
   "chained comparison 'X %0 Y %1 Z' does not behave the same as a mathematical expression">,
   InGroup<Parentheses>, DefaultError;
 
+def warn_comparison_in_fold_expression
+    : Warning<
+          "comparison in a fold expression would evaluate to '(X %0 Y) %0 Z' "
+          "which does not behave the same as a mathematical expression">,
+      InGroup<Parentheses>,
+      DefaultError;
----------------
AaronBallman wrote:

```suggestion
def warn_comparison_in_fold_expression : Warning<
  "comparison in fold expression would evaluate to '(X %0 Y) %0 Z' "
  "which does not behave the same as a mathematical expression">,
  InGroup<Parentheses>, DefaultError;
```

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


More information about the cfe-commits mailing list