@@ -19704,22 +19704,28 @@ static void buildLambdaCaptureFixit(Sema &Sema, LambdaScopeInfo *LSI,
19704
19704
}
19705
19705
}
19706
19706
19707
+ static DeclContext *ignoreReuquiresBodyDecl(DeclContext *DC) {
19708
+ if (isa_and_present<RequiresExprBodyDecl>(DC))
19709
+ return DC->getParent();
19710
+ return DC;
19711
+ }
19712
+
19707
19713
bool Sema::tryCaptureVariable(
19708
19714
ValueDecl *Var, SourceLocation ExprLoc, TryCaptureKind Kind,
19709
19715
SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType,
19710
19716
QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt) {
19711
19717
// An init-capture is notionally from the context surrounding its
19712
19718
// declaration, but its parent DC is the lambda class.
19713
19719
DeclContext *VarDC = Var->getDeclContext();
19714
- DeclContext *DC = CurContext;
19715
-
19716
19720
// tryCaptureVariable is called every time a DeclRef is formed,
19717
19721
// it can therefore have non-negigible impact on performances.
19718
19722
// For local variables and when there is no capturing scope,
19719
19723
// we can bailout early.
19720
- if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == DC ))
19724
+ if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == CurContext ))
19721
19725
return true;
19722
19726
19727
+ DeclContext *DC = ignoreReuquiresBodyDecl(CurContext);
19728
+
19723
19729
const auto *VD = dyn_cast<VarDecl>(Var);
19724
19730
if (VD) {
19725
19731
if (VD->isInitCapture())
@@ -19789,11 +19795,10 @@ bool Sema::tryCaptureVariable(
19789
19795
19790
19796
// Only block literals, captured statements, and lambda expressions can
19791
19797
// capture; other scopes don't work.
19792
- DeclContext *ParentDC =
19793
- !IsInScopeDeclarationContext
19794
- ? DC->getParent()
19795
- : getParentOfCapturingContextOrNull(DC, Var, ExprLoc,
19796
- BuildAndDiagnose, *this);
19798
+ DeclContext *ParentDC = IsInScopeDeclarationContext
19799
+ ? getParentOfCapturingContextOrNull(
19800
+ DC, Var, ExprLoc, BuildAndDiagnose, *this)
19801
+ : DC->getParent();
19797
19802
// We need to check for the parent *first* because, if we *have*
19798
19803
// private-captured a global variable, we need to recursively capture it in
19799
19804
// intermediate blocks, lambdas, etc.
0 commit comments