[PATCH] Make RecursiveASTVisitor::TraverseLambdaExpr call WalkUpFromLambdaExpr

James Dennett jdennett at google.com
Fri Jun 28 13:18:17 PDT 2013


jdennett added you to the CC list for the revision "Make RecursiveASTVisitor::TraverseLambdaExpr call WalkUpFromLambdaExpr".

Hi klimek, chandlerc,

This addresses a bug in RecursiveASTVisitor, which failed to call the Visit* functions on the LambdaExpr itself.

Per the documentation of RecursiveASTVisitor,  TraverseLambdaExpr should call WalkUpFromLambdaExpr.  

http://llvm-reviews.chandlerc.com/D1062

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/Tooling/RecursiveASTVisitorTest.cpp

Index: include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -2128,6 +2128,8 @@
 // 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) {
Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===================================================================
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -79,6 +79,14 @@
   }
 };
 
+class LambdaExprVisitor : public ExpectedLocationVisitor<LambdaExprVisitor> {
+public:
+  bool VisitLambdaExpr(LambdaExpr *Lambda) {
+    Match("", Lambda->getIntroducerRange().getBegin());
+    return true;
+  }
+};
+
 class TemplateArgumentLocTraverser
   : public ExpectedLocationVisitor<TemplateArgumentLocTraverser> {
 public:
@@ -150,15 +158,17 @@
   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) {
   VarDeclVisitor Visitor;
   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 @@
       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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1062.1.patch
Type: text/x-patch
Size: 2079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130628/667ea574/attachment.bin>


More information about the cfe-commits mailing list