From 9ad9959e51087cfe32692f61e951ba3dd6d71974 Mon Sep 17 00:00:00 2001 From: James Dennett Date: Sun, 30 Jun 2013 03:13:35 +0000 Subject: [PATCH] Bug fix: Make RecursiveASTVisitor::TraverseLambdaExpr call WalkUpFromLambdaExpr, so that the Visit* functions are called on that AST node. llvm-svn: 185277 --- clang/include/clang/AST/RecursiveASTVisitor.h | 2 ++ clang/tools/libclang/RecursiveASTVisitor.h | 2 ++ .../Tooling/RecursiveASTVisitorTest.cpp | 21 +++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index df71bffe8507..09ac4766968c 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2128,6 +2128,8 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, { // Walk only the visible parts of lambda expressions. template bool RecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { + TRY_TO(WalkUpFromLambdaExpr(S)); + for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), CEnd = S->explicit_capture_end(); C != CEnd; ++C) { diff --git a/clang/tools/libclang/RecursiveASTVisitor.h b/clang/tools/libclang/RecursiveASTVisitor.h index 17d70d6212ef..288d0ab66264 100644 --- a/clang/tools/libclang/RecursiveASTVisitor.h +++ b/clang/tools/libclang/RecursiveASTVisitor.h @@ -2047,6 +2047,8 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, { // Walk only the visible parts of lambda expressions. template bool RecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { + TRY_TO(WalkUpFromLambdaExpr(S)); + for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), CEnd = S->explicit_capture_end(); C != CEnd; ++C) { diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp index 81be19003b2a..2d226fddfc47 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -79,6 +79,14 @@ public: } }; +class LambdaExprVisitor : public ExpectedLocationVisitor { +public: + bool VisitLambdaExpr(LambdaExpr *Lambda) { + Match("", Lambda->getIntroducerRange().getBegin()); + return true; + } +}; + class TemplateArgumentLocTraverser : public ExpectedLocationVisitor { public: @@ -150,7 +158,8 @@ TEST(RecursiveASTVisitor, VisitsCXXForRangeStmtRange) { Visitor.ExpectMatch("x", 2, 30); EXPECT_TRUE(Visitor.runOver( "int x[5];\n" - "void f() { for (int i : x) { x[0] = 1; } }")); + "void f() { for (int i : x) { x[0] = 1; } }", + DeclRefExprVisitor::Lang_CXX11)); } TEST(RecursiveASTVisitor, VisitsCXXForRangeStmtLoopVariable) { @@ -158,7 +167,8 @@ TEST(RecursiveASTVisitor, VisitsCXXForRangeStmtLoopVariable) { Visitor.ExpectMatch("i", 2, 17); EXPECT_TRUE(Visitor.runOver( "int x[5];\n" - "void f() { for (int i : x) {} }")); + "void f() { for (int i : x) {} }", + VarDeclVisitor::Lang_CXX11)); } TEST(RecursiveASTVisitor, VisitsCallExpr) { @@ -461,4 +471,11 @@ TEST(RecursiveASTVisitor, VisitsCompoundLiteralType) { TypeLocVisitor::Lang_C)); } +TEST(RecursiveASTVisitor, VisitsLambdaExpr) { + LambdaExprVisitor Visitor; + Visitor.ExpectMatch("", 1, 12); + EXPECT_TRUE(Visitor.runOver("void f() { []{ return; }(); }", + LambdaExprVisitor::Lang_CXX11)); +} + } // end namespace clang