[clang-tools-extra] [clang-tidy] Fix assignment-in-if-condition false positive in statement expressions (PR #231704)
Daniil Dudkin via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 16:01:08 PDT 2026
================
@@ -80,6 +80,33 @@ void f5(int arg) {
v = f;
}
+void f6(int arg) {
+ int x;
+ if (({ x = 5; }))
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+ return;
+}
+
+void f7(int arg) {
+ if (({ int r; r = arg; (r = 1); }))
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+ return;
+}
+
+void f8(int arg) {
+ if (({ label: arg = 1; }))
+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+ return;
+}
+
+int get_value();
+
+void f9(int arg) {
+ if (({ [[clang::nomerge]] arg = get_value(); }))
+ // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+ return;
+}
----------------
unterumarmung wrote:
Why do we need this test case? How is it different from the `f6` one?
https://github.com/llvm/llvm-project/pull/231704
More information about the cfe-commits
mailing list