[clang-tools-extra] r277339 - [clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

Martin Bohme via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 1 04:29:17 PDT 2016


Author: mboehme
Date: Mon Aug  1 06:29:17 2016
New Revision: 277339

URL: http://llvm.org/viewvc/llvm-project?rev=277339&view=rev
Log:
[clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

Summary:
D22566 will change RecursiveASTVisitor so that it descends into the initialization expressions for lambda captures.

modernize-loop-convert needs to be prepared for this so that it does not interpret these initialization expressions as invalid uses of the loop variable. The change has no ill effects without D22566 in place, i.e. the change does not depend on D22566.

Reviewers: klimek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D22903

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=277339&r1=277338&r2=277339&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Mon Aug  1 06:29:17 2016
@@ -805,6 +805,18 @@ bool ForLoopIndexUseVisitor::VisitDeclSt
 }
 
 bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
+  // If this is an initialization expression for a lambda capture, prune the
+  // traversal so that we don't end up diagnosing the contained DeclRefExpr as
+  // inconsistent usage. No need to record the usage here -- this is done in
+  // TraverseLambdaCapture().
+  if (const auto *LE = dyn_cast_or_null<LambdaExpr>(NextStmtParent)) {
+    // Any child of a LambdaExpr that isn't the body is an initialization
+    // expression.
+    if (S != LE->getBody()) {
+      return true;
+    }
+  }
+
   // All this pointer swapping is a mechanism for tracking immediate parentage
   // of Stmts.
   const Stmt *OldNextParent = NextStmtParent;




More information about the cfe-commits mailing list