[cfe-commits] r151082 - in /cfe/trunk: lib/Sema/SemaLambda.cpp test/SemaCXX/lambda-expressions.cpp
Douglas Gregor
dgregor at apple.com
Tue Feb 21 12:05:31 PST 2012
Author: dgregor
Date: Tue Feb 21 14:05:31 2012
New Revision: 151082
URL: http://llvm.org/viewvc/llvm-project?rev=151082&view=rev
Log:
Only pop the expression evaluation context corresponding to a lambda
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.
Modified:
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/SemaCXX/lambda-expressions.cpp
Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=151082&r1=151081&r2=151082&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Tue Feb 21 14:05:31 2012
@@ -511,10 +511,6 @@
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 @@
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 @@
ActOnFields(0, Class->getLocation(), Class, Fields,
SourceLocation(), SourceLocation(), 0);
CheckCompletedCXXClass(Class);
-
}
if (LambdaExprNeedsCleanups)
Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=151082&r1=151081&r2=151082&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Tue Feb 21 14:05:31 2012
@@ -87,3 +87,17 @@
[]() { 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, [](){});
+ }
+}
More information about the cfe-commits
mailing list