diff options
| author | Martin Bohme <mboehme@google.com> | 2016-08-01 11:29:17 +0000 |
|---|---|---|
| committer | Martin Bohme <mboehme@google.com> | 2016-08-01 11:29:17 +0000 |
| commit | d10be623838db6d82c7ede9ea5d4cf267ff2dc8f (patch) | |
| tree | ef5e6e9750bfbc2ba2e1379d443376001b39794b | |
| parent | 0b9b81412fd66c32c5cd352bdfff6bbc0d3e8620 (diff) | |
| download | bcm5719-llvm-d10be623838db6d82c7ede9ea5d4cf267ff2dc8f.tar.gz bcm5719-llvm-d10be623838db6d82c7ede9ea5d4cf267ff2dc8f.zip | |
[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
llvm-svn: 277339
| -rw-r--r-- | clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index 3fee2c44c7e..55ca0d784c4 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -805,6 +805,18 @@ bool ForLoopIndexUseVisitor::VisitDeclStmt(DeclStmt *S) { } 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; |

