[clang-tools-extra] [clang-tidy] Improve `bugprone-infinite-loop` check by adding handing for structured bindings (PR #144213)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 16 23:46:49 PDT 2025


================
@@ -83,6 +83,23 @@ static bool isVarThatIsPossiblyChanged(const Decl *Func, const Stmt *LoopStmt,
              isChanged(LoopStmt, Var, Context);
       // FIXME: Track references.
     }
+
+    if (const auto *BD = dyn_cast<BindingDecl>(DRE->getDecl())) {
+      if (const auto *DD =
+              dyn_cast<DecompositionDecl>(BD->getDecomposedDecl())) {
+        if (!DD->isLocalVarDeclOrParm())
+          return true;
+
+        if (DD->getType().isVolatileQualified())
+          return true;
+
+        if (!BD->getType().getTypePtr()->isIntegerType())
+          return true;
+
+        return hasPtrOrReferenceInFunc(Func, BD) ||
+               isChanged(LoopStmt, BD, Context);
----------------
HerrCai0907 wrote:

avoid duplicated code with `VarDecl` part. extract them to separated function

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


More information about the cfe-commits mailing list