diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2012-02-11 02:51:16 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2012-02-11 02:51:16 +0000 |
commit | 668165ab1e604b063c0aa0df8ff91c80879670bf (patch) | |
tree | 5528d576fe6e69f4af6bacaa1d1bf408e406b8f0 /lib/Sema/SemaExprCXX.cpp | |
parent | b70a3bad9c767b3cdeadf363d4dbe8ad25a26588 (diff) |
Make sure Sema creates a field for 'this' captures. (Doug, please double-check that this is correct.)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150292 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 5a2a827230..c16d7e2282 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -707,8 +707,22 @@ void Sema::CheckCXXThisCapture(SourceLocation Loc, bool Explicit) { for (unsigned idx = FunctionScopes.size() - 1; NumClosures; --idx, --NumClosures) { CapturingScopeInfo *CSI = cast<CapturingScopeInfo>(FunctionScopes[idx]); + Expr *ThisExpr = 0; + if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(CSI)) { + // For lambda expressions, build a field and an initializing expression. + QualType ThisTy = getCurrentThisType(); + CXXRecordDecl *Lambda = LSI->Lambda; + FieldDecl *Field + = FieldDecl::Create(Context, Lambda, Loc, Loc, 0, ThisTy, + Context.getTrivialTypeSourceInfo(ThisTy, Loc), + 0, false, false); + Field->setImplicit(true); + Field->setAccess(AS_private); + Lambda->addDecl(Field); + ThisExpr = new (Context) CXXThisExpr(Loc, ThisTy, /*isImplicit=*/true); + } bool isNested = NumClosures > 1; - CSI->AddThisCapture(isNested, Loc); + CSI->AddThisCapture(isNested, Loc, ThisExpr); } } |