[PATCH] D56665: [AST] Fix double-traversal of code in top-level lambdas in RAV(implicit = yes).
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 14 09:20:06 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL351075: [AST] Fix double-traversal of code in top-level lambdas in RAV(implicit = yes). (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56665/new/
https://reviews.llvm.org/D56665
Files:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp
Index: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp
@@ -65,6 +65,17 @@
EXPECT_FALSE(Visitor.allClassesHaveBeenTraversed());
}
+TEST(RecursiveASTVisitor, TopLevelLambda) {
+ LambdaExprVisitor Visitor;
+ Visitor.VisitImplicitCode = true;
+ Visitor.ExpectMatch("", 1, 10);
+ Visitor.ExpectMatch("", 1, 14);
+ EXPECT_TRUE(Visitor.runOver("auto x = []{ [] {}; };",
+ LambdaExprVisitor::Lang_CXX11));
+ EXPECT_TRUE(Visitor.allBodiesHaveBeenTraversed());
+ EXPECT_TRUE(Visitor.allClassesHaveBeenTraversed());
+}
+
TEST(RecursiveASTVisitor, VisitsLambdaExprAndImplicitClass) {
LambdaExprVisitor Visitor;
Visitor.VisitImplicitCode = true;
Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -1368,9 +1368,14 @@
template <typename Derived>
bool RecursiveASTVisitor<Derived>::canIgnoreChildDeclWhileTraversingDeclContext(
const Decl *Child) {
- // BlockDecls and CapturedDecls are traversed through BlockExprs and
- // CapturedStmts respectively.
- return isa<BlockDecl>(Child) || isa<CapturedDecl>(Child);
+ // BlockDecls are traversed through BlockExprs,
+ // CapturedDecls are traversed through CapturedStmts.
+ if (isa<BlockDecl>(Child) || isa<CapturedDecl>(Child))
+ return true;
+ // Lambda classes are traversed through LambdaExprs.
+ if (const CXXRecordDecl* Cls = dyn_cast<CXXRecordDecl>(Child))
+ return Cls->isLambda();
+ return false;
}
template <typename Derived>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56665.181570.patch
Type: text/x-patch
Size: 1860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190114/c720c341/attachment.bin>
More information about the cfe-commits
mailing list