r185277 - Bug fix: Make RecursiveASTVisitor<T>::TraverseLambdaExpr call

James Dennett jdennett at google.com
Sat Jun 29 20:13:35 PDT 2013


Author: jdennett
Date: Sat Jun 29 22:13:35 2013
New Revision: 185277

URL: http://llvm.org/viewvc/llvm-project?rev=185277&view=rev
Log:
Bug fix: Make RecursiveASTVisitor<T>::TraverseLambdaExpr call
WalkUpFromLambdaExpr, so that the Visit* functions are called
on that AST node.

Modified:
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
    cfe/trunk/tools/libclang/RecursiveASTVisitor.h
    cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=185277&r1=185276&r2=185277&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Sat Jun 29 22:13:35 2013
@@ -2128,6 +2128,8 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr
 // Walk only the visible parts of lambda expressions.  
 template<typename Derived>
 bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
+  TRY_TO(WalkUpFromLambdaExpr(S));
+
   for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
                                  CEnd = S->explicit_capture_end();
        C != CEnd; ++C) {

Modified: cfe/trunk/tools/libclang/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=185277&r1=185276&r2=185277&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/RecursiveASTVisitor.h (original)
+++ cfe/trunk/tools/libclang/RecursiveASTVisitor.h Sat Jun 29 22:13:35 2013
@@ -2047,6 +2047,8 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr
 // Walk only the visible parts of lambda expressions.  
 template<typename Derived>
 bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
+  TRY_TO(WalkUpFromLambdaExpr(S));
+
   for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
                                  CEnd = S->explicit_capture_end();
        C != CEnd; ++C) {

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=185277&r1=185276&r2=185277&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Sat Jun 29 22:13:35 2013
@@ -79,6 +79,14 @@ public:
   }
 };
 
+class LambdaExprVisitor : public ExpectedLocationVisitor<LambdaExprVisitor> {
+public:
+  bool VisitLambdaExpr(LambdaExpr *Lambda) {
+    Match("", Lambda->getIntroducerRange().getBegin());
+    return true;
+  }
+};
+
 class TemplateArgumentLocTraverser
   : public ExpectedLocationVisitor<TemplateArgumentLocTraverser> {
 public:
@@ -150,7 +158,8 @@ TEST(RecursiveASTVisitor, VisitsCXXForRa
   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, VisitsCXXForRa
   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, VisitsCompound
       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





More information about the cfe-commits mailing list