[llvm-branch-commits] [clang] aaf23ab - Fix traversal with hasDescendant into lambdas
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Feb 15 19:02:37 PST 2021
Author: Stephen Kelly
Date: 2021-02-15T18:58:36-08:00
New Revision: aaf23abe9d57af638644cedbc1ca6132f140a57d
URL: https://github.com/llvm/llvm-project/commit/aaf23abe9d57af638644cedbc1ca6132f140a57d
DIFF: https://github.com/llvm/llvm-project/commit/aaf23abe9d57af638644cedbc1ca6132f140a57d.diff
LOG: Fix traversal with hasDescendant into lambdas
Differential Revision: https://reviews.llvm.org/D95607
(cherry picked from commit bb57a3422a09dcdd572ccb42767a0dabb5f966dd)
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 llvm-branch-commits
mailing list