]> granicus.if.org Git - clang/commitdiff
Only pop the expression evaluation context corresponding to a lambda
authorDouglas Gregor <dgregor@apple.com>
Tue, 21 Feb 2012 20:05:31 +0000 (20:05 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 21 Feb 2012 20:05:31 +0000 (20:05 +0000)
expression after we've finished the function body of the corresponding
function call operator. Otherwise, ActOnFinishFunctionBody() will see
the (unfinished) evaluation context of the lambda expression
itself. Fixes PR12031.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151082 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLambda.cpp
test/SemaCXX/lambda-expressions.cpp

index 42040084e10eb6f3973105765b65514e8dccdf38..016322fe5237c749fca54ded047d1635042df6c1 100644 (file)
@@ -511,10 +511,6 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
                                  llvm::Optional<unsigned> ManglingNumber,
                                  Decl *ContextDecl,
                                  bool IsInstantiation) {
-  // Leave the expression-evaluation context.
-  DiscardCleanupsInEvaluationContext();
-  PopExpressionEvaluationContext();
-
   // Collect information from the lambda scope.
   llvm::SmallVector<LambdaExpr::Capture, 4> Captures;
   llvm::SmallVector<Expr *, 4> CaptureInits;
@@ -631,6 +627,7 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
     ActOnFinishFunctionBody(CallOperator, Body, IsInstantiation);
     CallOperator->setLexicalDeclContext(Class);
     Class->addDecl(CallOperator);
+    PopExpressionEvaluationContext();
 
     // C++11 [expr.prim.lambda]p6:
     //   The closure type for a lambda-expression with no lambda-capture
@@ -654,7 +651,6 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
     ActOnFields(0, Class->getLocation(), Class, Fields, 
                 SourceLocation(), SourceLocation(), 0);
     CheckCompletedCXXClass(Class);
-
   }
 
   if (LambdaExprNeedsCleanups)
index b54da37014b3cd433c86c41025d1e3ccd3927e3d..1358d9e2a3911e52d2010b0acc328e90b17d5473 100644 (file)
@@ -87,3 +87,17 @@ namespace ImplicitCapture {
     []() { return h; }; // expected-error {{variable 'h' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} 
   }
 }
+
+namespace PR12031 {
+  struct X {
+    template<typename T>
+    X(const T&);
+    ~X();
+  };
+
+  void f(int i, X x);
+  void g() {
+    const int v = 10;
+    f(v, [](){});
+  }
+}