diff options
| -rw-r--r-- | clang/lib/Sema/SemaLambda.cpp | 6 | ||||
| -rw-r--r-- | clang/test/SemaCXX/lambda-expressions.cpp | 14 | 
2 files changed, 15 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 42040084e10..016322fe523 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -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) diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index b54da37014b..1358d9e2a39 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/test/SemaCXX/lambda-expressions.cpp @@ -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, [](){}); +  } +}  | 

