[clang] [clang] Added warn-assignment-bool-context (PR #115234)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 07:19:44 PST 2025
================
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wparentheses -verify %s
+
+// Do not emit the warning for compound-assignments.
+bool f(int x) { return x = 0; } // expected-warning {{suggest parentheses around assignment used as truth value}} \
+ // expected-note{{place parentheses around the assignment to silence this warning}}
+bool f2(int x) { return x += 0; }
+
+bool f3(bool x) { return x = 0; }
+
+void test() {
+ int x;
+
+ // Assignemnts inside of conditions should still emit the more specific `warn_condition_is_assignment` warning.
----------------
erichkeane wrote:
```suggestion
// Assignments inside of conditions should still emit the more specific `warn_condition_is_assignment` warning.
```
https://github.com/llvm/llvm-project/pull/115234
More information about the cfe-commits
mailing list