[PATCH] D95607: Fix traversal with hasDescendant into lambdas
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 30 05:58:33 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb57a3422a09: Fix traversal with hasDescendant into lambdas (authored by stephenkelly).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95607/new/
https://reviews.llvm.org/D95607
Files:
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -3220,6 +3220,12 @@
float i = 42.0;
}
+void func15() {
+ int count = 0;
+ auto l = [&] { ++count; };
+ (void)l;
+}
+
)cpp";
EXPECT_TRUE(
@@ -3404,6 +3410,15 @@
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;
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -295,7 +295,7 @@
if (!match(*Node->getBody()))
return false;
- return true;
+ return VisitorBase::TraverseStmt(Node->getBody());
}
bool shouldVisitTemplateInstantiations() const { return true; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95607.320298.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210130/574675cb/attachment.bin>
More information about the cfe-commits
mailing list