OSDN Git Service

Fix traversal with hasDescendant into lambdas
authorStephen Kelly <steveire@gmail.com>
Thu, 28 Jan 2021 13:12:43 +0000 (13:12 +0000)
committerTom Stellard <tstellar@redhat.com>
Tue, 16 Feb 2021 02:58:36 +0000 (18:58 -0800)
Differential Revision: https://reviews.llvm.org/D95607

(cherry picked from commit bb57a3422a09dcdd572ccb42767a0dabb5f966dd)

clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

index 89e83ee..41be373 100644 (file)
@@ -295,7 +295,7 @@ public:
     if (!match(*Node->getBody()))
       return false;
 
-    return true;
+    return VisitorBase::TraverseStmt(Node->getBody());
   }
 
   bool shouldVisitTemplateInstantiations() const { return true; }
index cbea274..c67c40e 100644 (file)
@@ -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;