diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-09 08:14:43 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-09 08:14:43 +0000 |
commit | e2c5913c48f66bfec9e58a8ad1d90e5eeffad586 (patch) | |
tree | af3426a28595a628dcd322a29f51ab9b22a322d8 /lib/Sema/SemaLambda.cpp | |
parent | 621fc4b47f11585120e3d2eed32d1f46e2063c62 (diff) |
Implement C++ [expr.prim.lambda]p2, which bans lambda expressions in
unevaluated operands. Be certain that we're marking everything
referenced within a capture initializer as odr-used.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150163 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLambda.cpp')
-rw-r--r-- | lib/Sema/SemaLambda.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index 776d27a364..afc4d5de27 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -357,9 +357,28 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, if (LambdaExprNeedsCleanups) ExprNeedsCleanups = true; - Expr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, - CaptureDefault, Captures, ExplicitParams, - CaptureInits, Body->getLocEnd()); + LambdaExpr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, + CaptureDefault, Captures, + ExplicitParams, CaptureInits, + Body->getLocEnd()); + + // C++11 [expr.prim.lambda]p2: + // A lambda-expression shall not appear in an unevaluated operand + // (Clause 5). + switch (ExprEvalContexts.back().Context) { + case Unevaluated: + // We don't actually diagnose this case immediately, because we + // could be within a context where we might find out later that + // the expression is potentially evaluated (e.g., for typeid). + ExprEvalContexts.back().Lambdas.push_back(Lambda); + break; + + case ConstantEvaluated: + case PotentiallyEvaluated: + case PotentiallyEvaluatedIfUsed: + break; + } + Diag(StartLoc, diag::err_lambda_unsupported); return MaybeBindToTemporary(Lambda); |