r181046 - PR15906: The body of a lambda is not an evaluated subexpression; don't visit it when visiting such subexpressions.

Richard Smith richard-llvm at metafoo.co.uk
Fri May 3 12:16:23 PDT 2013


Author: rsmith
Date: Fri May  3 14:16:22 2013
New Revision: 181046

URL: http://llvm.org/viewvc/llvm-project?rev=181046&view=rev
Log:
PR15906: The body of a lambda is not an evaluated subexpression; don't visit it when visiting such subexpressions.

Modified:
    cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/uninitialized.cpp

Modified: cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h?rev=181046&r1=181045&r2=181046&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h (original)
+++ cfe/trunk/include/clang/AST/EvaluatedExprVisitor.h Fri May  3 14:16:22 2013
@@ -55,7 +55,7 @@ public:
     // Only the selected subexpression matters; the other one is not evaluated.
     return this->Visit(E->getChosenSubExpr(Context));
   }
-                 
+
   void VisitDesignatedInitExpr(DesignatedInitExpr *E) {
     // Only the actual initializer matters; the designators are all constant
     // expressions.
@@ -72,6 +72,15 @@ public:
       return static_cast<ImplClass*>(this)->VisitExpr(CE);
   }
 
+  void VisitLambdaExpr(LambdaExpr *LE) {
+    // Only visit the capture initializers, and not the body.
+    for (LambdaExpr::capture_init_iterator I = LE->capture_init_begin(),
+                                           E = LE->capture_init_end();
+         I != E; ++I)
+      if (*I)
+        this->Visit(*I);
+  }
+
   /// \brief The basis case walks all of the children of the statement or
   /// expression, assuming they are all potentially evaluated.
   void VisitStmt(Stmt *S) {

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=181046&r1=181045&r2=181046&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May  3 14:16:22 2013
@@ -7212,7 +7212,7 @@ namespace {
         return;
       }
       Inherited::VisitUnaryOperator(E);
-    } 
+    }
 
     void VisitObjCMessageExpr(ObjCMessageExpr *E) { return; }
 

Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=181046&r1=181045&r2=181046&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Fri May  3 14:16:22 2013
@@ -511,3 +511,15 @@ namespace operators {
 
   int x = x = 5;
 }
+
+namespace lambdas {
+  struct A {
+    template<typename T> A(T) {}
+    int x;
+  };
+  A a0([] { return a0.x; }); // ok
+  void f() { 
+    A a1([=] { return a1.x; }); // expected-warning{{variable 'a1' is uninitialized when used within its own initialization}}
+    A a2([&] { return a2.x; }); // ok
+  }
+}





More information about the cfe-commits mailing list