[PATCH] D95607: Fix traversal with hasDescendant into lambdas
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; } 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; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95607: Fix traversal with hasDescendant into lambdas
alexfh accepted this revision. alexfh added a comment. This revision is now accepted and ready to land. Looks good! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95607/new/ https://reviews.llvm.org/D95607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95607: Fix traversal with hasDescendant into lambdas
steveire created this revision. steveire added a reviewer: aaron.ballman. steveire requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo 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 @@ -3184,6 +3184,12 @@ float i = 42.0; } +void func15() { + int count = 0; + auto l = [&] { ++count; }; + (void)l; +} + )cpp"; EXPECT_TRUE( @@ -3368,6 +3374,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; } Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp === --- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -3184,6 +3184,12 @@ float i = 42.0; } +void func15() { + int count = 0; + auto l = [&] { ++count; }; + (void)l; +} + )cpp"; EXPECT_TRUE( @@ -3368,6 +3374,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; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits