[clang-tools-extra] [clang-tidy] Fix assignment-in-if-condition false positive in statement expressions (PR #231704)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 15 00:18:41 PDT 2026


================
@@ -45,6 +45,23 @@ void AssignmentInIfConditionCheck::check(
           return true;
         }
 
+        // Only traverse the result expression of a statement expression,
+        // looking through labels and attributes on the last statement.
+        bool TraverseStmtExpr(StmtExpr *SE,
+                              DataRecursionQueue *Queue = nullptr) {
+          Stmt *Last = SE->getSubStmt()->body_back();
+          while (Last && !isa<Expr>(Last))
+            if (auto *LS = dyn_cast<LabelStmt>(Last))
+              Last = LS->getSubStmt();
+            else if (auto *AS = dyn_cast<AttributedStmt>(Last))
+              Last = AS->getSubStmt();
+            else
+              return true;
----------------
mark-zilber wrote:

Yes, we can. Switched to ValueStmt::getExprStmt().

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


More information about the cfe-commits mailing list