[clang] bb57a34 - Fix traversal with hasDescendant into lambdas
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 30 05:58:15 PST 2021
Author: Stephen Kelly
Date: 2021-01-30T13:57:41Z
New Revision: bb57a3422a09dcdd572ccb42767a0dabb5f966dd
URL: https://github.com/llvm/llvm-project/commit/bb57a3422a09dcdd572ccb42767a0dabb5f966dd
DIFF: https://github.com/llvm/llvm-project/commit/bb57a3422a09dcdd572ccb42767a0dabb5f966dd.diff
LOG: Fix traversal with hasDescendant into lambdas
Differential Revision: https://reviews.llvm.org/D95607
Added:
Modified:
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 89e83ee61574..41be3738e707 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -295,7 +295,7 @@ class MatchChildASTVisitor
if (!match(*Node->getBody()))
return false;
- return true;
+ return VisitorBase::TraverseStmt(Node->getBody());
}
bool shouldVisitTemplateInstantiations() const { return true; }
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index cbea274cecc9..c67c40ed960a 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3220,6 +3220,12 @@ void func14() {
float i = 42.0;
}
+void func15() {
+ int count = 0;
+ auto l = [&] { ++count; };
+ (void)l;
+}
+
)cpp";
EXPECT_TRUE(
@@ -3404,6 +3410,15 @@ void func14() {
functionDecl(hasName("func14"), hasDescendant(floatLiteral()))),
langCxx20OrLater()));
+ EXPECT_TRUE(matches(
+ Code,
+ traverse(TK_IgnoreUnlessSpelledInSource,
+ compoundStmt(
+ hasDescendant(varDecl(hasName("count")).bind("countVar")),
+ hasDescendant(
+ declRefExpr(to(varDecl(equalsBoundNode("countVar"))))))),
+ langCxx20OrLater()));
+
Code = R"cpp(
void foo() {
int explicit_captured = 0;
More information about the cfe-commits
mailing list