return BuildLambdaExpr(StartLoc, Body->getLocEnd(), &LSI);
}
+static LambdaCaptureDefault
+mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS) {
+ switch (ICS) {
+ case CapturingScopeInfo::ImpCap_None:
+ return LCD_None;
+ case CapturingScopeInfo::ImpCap_LambdaByval:
+ return LCD_ByCopy;
+ case CapturingScopeInfo::ImpCap_CapturedRegion:
+ case CapturingScopeInfo::ImpCap_LambdaByref:
+ return LCD_ByRef;
+ case CapturingScopeInfo::ImpCap_Block:
+ llvm_unreachable("block capture in lambda");
+ }
+ llvm_unreachable("Unknown implicit capture style");
+}
+
ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
LambdaScopeInfo *LSI) {
// Collect information from the lambda scope.
SmallVector<LambdaCapture, 4> Captures;
SmallVector<Expr *, 4> CaptureInits;
- LambdaCaptureDefault CaptureDefault = LCD_None;
- SourceLocation CaptureDefaultLoc;
+ SourceLocation CaptureDefaultLoc = LSI->CaptureDefaultLoc;
+ LambdaCaptureDefault CaptureDefault =
+ mapImplicitCaptureStyle(LSI->ImpCaptureStyle);
CXXRecordDecl *Class;
CXXMethodDecl *CallOperator;
SourceRange IntroducerRange;
CaptureInits.push_back(Init);
}
- switch (LSI->ImpCaptureStyle) {
- case CapturingScopeInfo::ImpCap_None:
- CaptureDefault = LCD_None;
- break;
-
- case CapturingScopeInfo::ImpCap_LambdaByval:
- CaptureDefault = LCD_ByCopy;
- break;
-
- case CapturingScopeInfo::ImpCap_CapturedRegion:
- case CapturingScopeInfo::ImpCap_LambdaByref:
- CaptureDefault = LCD_ByRef;
- break;
-
- case CapturingScopeInfo::ImpCap_Block:
- llvm_unreachable("block capture in lambda");
- break;
- }
- CaptureDefaultLoc = LSI->CaptureDefaultLoc;
-
// C++11 [expr.prim.lambda]p6:
// The closure type for a lambda-expression with no lambda-capture
// has a public non-virtual non-explicit const conversion function