/// \brief The class that describes the lambda.
CXXRecordDecl *Lambda;
+ /// \brief The class that describes the lambda.
+ CXXMethodDecl *CallOperator;
+
/// \brief Source range covering the lambda introducer [...].
SourceRange IntroducerRange;
/// \brief Whether the (empty) parameter list is explicit.
bool ExplicitParams;
- LambdaScopeInfo(DiagnosticsEngine &Diag, CXXRecordDecl *Lambda)
+ LambdaScopeInfo(DiagnosticsEngine &Diag, CXXRecordDecl *Lambda,
+ CXXMethodDecl *CallOperator)
: CapturingScopeInfo(Diag, ImpCap_None), Lambda(Lambda),
- NumExplicitCaptures(0), Mutable(false)
+ CallOperator(CallOperator), NumExplicitCaptures(0), Mutable(false)
{
Kind = SK_Lambda;
}
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
/*Args=*/0, /*NumArgs=*/0, EPI);
MethodTyInfo = Context.getTrivialTypeSourceInfo(MethodTy);
ExplicitParams = false;
+ EndLoc = Intro.Range.getEnd();
} else {
assert(ParamInfo.isFunctionDeclarator() &&
"lambda-declarator is a function");
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:
// 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.
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;
DiscardCleanupsInEvaluationContext();
PopExpressionEvaluationContext();
- // Leave the context of the lambda.
- PopDeclContext();
-
// FIXME: End-of-lambda checking
// Collect information from the lambda scope.
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,