[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
================
@@ -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;
----------------
unterumarmung wrote:
Could we simplify this loop by using `ValueStmt::getExprStmt()`? It seems to already handle unwrapping `LabelStmt` and `AttributedStmt`.
https://github.com/llvm/llvm-project/pull/231704
More information about the cfe-commits
mailing list