@@ -4793,6 +4793,84 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
4793
4793
Class->startDefinition ();
4794
4794
CurContext->addDecl (Class);
4795
4795
4796
+ // Introduce the lambda scope.
4797
+ PushLambdaScope (Class);
4798
+
4799
+ LambdaScopeInfo *LSI = getCurLambda ();
4800
+
4801
+ QualType ThisCaptureType;
4802
+ llvm::DenseMap<const IdentifierInfo*, SourceLocation> CapturesSoFar;
4803
+ for (llvm::SmallVector<LambdaCapture, 4 >::const_iterator
4804
+ C = Intro.Captures .begin (), E = Intro.Captures .end (); C != E; ++C) {
4805
+ if (C->Kind == LCK_This) {
4806
+ if (!ThisCaptureType.isNull ()) {
4807
+ Diag (C->Loc , diag::err_capture_more_than_once) << " 'this'" ;
4808
+ continue ;
4809
+ }
4810
+
4811
+ if (Intro.Default == LCD_ByCopy) {
4812
+ Diag (C->Loc , diag::err_this_capture_with_copy_default);
4813
+ continue ;
4814
+ }
4815
+
4816
+ ThisCaptureType = getCurrentThisType ();
4817
+
4818
+ if (ThisCaptureType.isNull ()) {
4819
+ Diag (C->Loc , diag::err_invalid_this_use);
4820
+ continue ;
4821
+ }
4822
+ LSI->Captures .push_back (LambdaScopeInfo::Capture::ThisCapture);
4823
+ continue ;
4824
+ }
4825
+
4826
+ assert (C->Id && " missing identifier for capture" );
4827
+
4828
+ if (C->Kind == LCK_ByRef && Intro.Default == LCD_ByRef) {
4829
+ Diag (C->Loc , diag::err_reference_capture_with_reference_default);
4830
+ continue ;
4831
+ } else if (C->Kind == LCK_ByCopy && Intro.Default == LCD_ByCopy) {
4832
+ Diag (C->Loc , diag::err_copy_capture_with_copy_default);
4833
+ continue ;
4834
+ }
4835
+
4836
+ llvm::DenseMap<const IdentifierInfo*, SourceLocation>::iterator Appearance;
4837
+ bool IsFirstAppearance;
4838
+ llvm::tie (Appearance, IsFirstAppearance)
4839
+ = CapturesSoFar.insert (std::make_pair (C->Id , C->Loc ));
4840
+
4841
+ if (!IsFirstAppearance) {
4842
+ Diag (C->Loc , diag::err_capture_more_than_once) << C->Id ;
4843
+ continue ;
4844
+ }
4845
+
4846
+ DeclarationNameInfo Name (C->Id , C->Loc );
4847
+ LookupResult R (*this , Name, LookupOrdinaryName);
4848
+ CXXScopeSpec ScopeSpec;
4849
+ LookupParsedName (R, CurScope, &ScopeSpec);
4850
+ if (R.isAmbiguous ())
4851
+ continue ;
4852
+ if (R.empty ())
4853
+ if (DiagnoseEmptyLookup (CurScope, ScopeSpec, R, CTC_Unknown))
4854
+ continue ;
4855
+
4856
+ VarDecl *Var = R.getAsSingle <VarDecl>();
4857
+ if (!Var) {
4858
+ Diag (C->Loc , diag::err_capture_does_not_name_variable) << C->Id ;
4859
+ continue ;
4860
+ }
4861
+
4862
+ if (!Var->hasLocalStorage ()) {
4863
+ Diag (C->Loc , diag::err_capture_non_automatic_variable) << C->Id ;
4864
+ continue ;
4865
+ }
4866
+
4867
+ // FIXME: Actually capturing a variable is much more complicated than this
4868
+ // in the general case; see shouldCaptureValueReference.
4869
+ // FIXME: Should we be building a DeclRefExpr here? We don't really need
4870
+ // it until the point where we're actually building the LambdaExpr.
4871
+ LSI->Captures .push_back (LambdaScopeInfo::Capture (Var, C->Kind ));
4872
+ }
4873
+
4796
4874
// Build the call operator; we don't really have all the relevant information
4797
4875
// at this point, but we need something to attach child declarations to.
4798
4876
QualType MethodTy;
@@ -4837,17 +4915,12 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
4837
4915
4838
4916
ProcessDeclAttributes (CurScope, Method, ParamInfo);
4839
4917
4840
- // Introduce the lambda scope.
4841
- PushLambdaScope (Class);
4842
-
4843
4918
// Enter a new evaluation context to insulate the block from any
4844
4919
// cleanups from the enclosing full-expression.
4845
4920
PushExpressionEvaluationContext (PotentiallyEvaluated);
4846
4921
4847
4922
PushDeclContext (CurScope, Method);
4848
4923
4849
- LambdaScopeInfo *LSI = getCurLambda ();
4850
-
4851
4924
// Set the parameters on the decl, if specified.
4852
4925
if (isa<FunctionProtoTypeLoc>(MethodTyInfo->getTypeLoc ())) {
4853
4926
FunctionProtoTypeLoc Proto =
0 commit comments