diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-08 20:17:14 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-08 20:17:14 +0000 |
commit | 76e3da57b0e8cf72d221f44d54566ef206341668 (patch) | |
tree | 50e02b99899599b547dfa8cb0b70fb5390a1ea2f /lib/Sema/SemaExprCXX.cpp | |
parent | b319e029a6a05a76023c1bb1ce77a6d567457838 (diff) |
When completing a lambda expression, make sure to check and attach the
body of the lambda to the function call operator.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150087 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index cd2c210a39..98ab97808c 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4896,6 +4896,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, QualType MethodTy; TypeSourceInfo *MethodTyInfo; bool ExplicitParams = true; + SourceLocation EndLoc; if (ParamInfo.getNumTypeObjects() == 0) { // C++11 [expr.prim.lambda]p4: // If a lambda-expression does not include a lambda-declarator, it is as @@ -4906,6 +4907,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, /*Args=*/0, /*NumArgs=*/0, EPI); MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy); ExplicitParams = false; + EndLoc = Intro.Range.getEnd(); } else { assert(ParamInfo.isFunctionDeclarator() && "lambda-declarator is a function"); @@ -4928,6 +4930,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, assert(MethodTyInfo && "no type from lambda-declarator"); MethodTy = MethodTyInfo->getType(); assert(!MethodTy.isNull() && "no type from lambda declarator"); + EndLoc = ParamInfo.getSourceRange().getEnd(); } // C++11 [expr.prim.lambda]p5: @@ -4937,19 +4940,22 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, // trailing-return-type respectively. DeclarationName MethodName = Context.DeclarationNames.getCXXOperatorName(OO_Call); + DeclarationNameLoc MethodNameLoc; + MethodNameLoc.CXXOperatorName.BeginOpNameLoc + = Intro.Range.getBegin().getRawEncoding(); + MethodNameLoc.CXXOperatorName.EndOpNameLoc + = Intro.Range.getEnd().getRawEncoding(); CXXMethodDecl *Method - = CXXMethodDecl::Create(Context, - Class, - ParamInfo.getSourceRange().getEnd(), - DeclarationNameInfo(MethodName, - /*NameLoc=*/SourceLocation()), - MethodTy, - MethodTyInfo, + = CXXMethodDecl::Create(Context, Class, EndLoc, + DeclarationNameInfo(MethodName, + Intro.Range.getBegin(), + MethodNameLoc), + MethodTy, MethodTyInfo, /*isStatic=*/false, SC_None, /*isInline=*/true, /*isConstExpr=*/false, - ParamInfo.getSourceRange().getEnd()); + EndLoc); Method->setAccess(AS_public); Class->addDecl(Method); Method->setLexicalDeclContext(DC); // FIXME: Minor hack. @@ -4963,7 +4969,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, PushDeclContext(CurScope, Method); // Introduce the lambda scope. - PushLambdaScope(Class); + PushLambdaScope(Class, Method); LambdaScopeInfo *LSI = getCurLambda(); if (Intro.Default == LCD_ByCopy) LSI->ImpCaptureStyle = LambdaScopeInfo::ImpCap_LambdaByval; @@ -5123,9 +5129,6 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, DiscardCleanupsInEvaluationContext(); PopExpressionEvaluationContext(); - // Leave the context of the lambda. - PopDeclContext(); - // FIXME: End-of-lambda checking // Collect information from the lambda scope. @@ -5184,7 +5187,10 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc, break; } - PopFunctionScopeInfo(); + // C++ [expr.prim.lambda]p7: + // The lambda-expression’s compound-statement yields the + // function-body (8.4) of the function call operator [...]. + ActOnFinishFunctionBody(LSI->CallOperator, Body, /*IsInstantation=*/false); } Expr *Lambda = LambdaExpr::Create(Context, Class, IntroducerRange, |