diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-05-16 17:01:33 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-05-16 17:01:33 +0000 |
commit | d57f52ca4d0e9d5d42dd6947d1e66d693625cf2c (patch) | |
tree | 2fccc81f2b9b7d2ce2da0dd34c2171db49b12356 /lib/Sema/SemaExpr.cpp | |
parent | 29a93f810ae5277446f610e8b6cdf0985febb989 (diff) |
Clean up r156925, so that we only mark the capturing DeclRefExpr of a
lambda as referring to a local in an enclosing scope if we're in the
enclosing scope of the lambda (not it's function call operator). Also,
turn the test into an IR generation test, since that's where the
crashes occurred. Really fixes PR12746 / <rdar://problem/11465120>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156926 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 440382bb5a..67b60fad51 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -10040,7 +10040,8 @@ diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI, VarDecl *Var, QualType FieldType, QualType DeclRefType, - SourceLocation Loc) { + SourceLocation Loc, + bool RefersToEnclosingLocal) { CXXRecordDecl *Lambda = LSI->Lambda; // Build the non-static data member. @@ -10069,8 +10070,8 @@ static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI, // C++ [expr.prim.labda]p12: // An entity captured by a lambda-expression is odr-used (3.2) in // the scope containing the lambda-expression. - Expr *Ref = new (S.Context) DeclRefExpr(Var, true, DeclRefType, - VK_LValue, Loc); + Expr *Ref = new (S.Context) DeclRefExpr(Var, RefersToEnclosingLocal, + DeclRefType, VK_LValue, Loc); Var->setReferenced(true); Var->setUsed(true); @@ -10413,7 +10414,8 @@ bool Sema::tryCaptureVariable(VarDecl *Var, SourceLocation Loc, Expr *CopyExpr = 0; if (BuildAndDiagnose) { ExprResult Result = captureInLambda(*this, LSI, Var, CaptureType, - DeclRefType, Loc); + DeclRefType, Loc, + I == N-1); if (!Result.isInvalid()) CopyExpr = Result.take(); } |