@@ -828,6 +828,9 @@ void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) {
828828 if (!Ctx.isInstantiationRecord ())
829829 ++NonInstantiationEntries;
830830
831+ if (Ctx.Kind != CodeSynthesisContext::ConstraintSubstitution)
832+ ++NonConstraintSubstitutionEntries;
833+
831834 // Check to see if we're low on stack space. We can't do anything about this
832835 // from here, but we can at least warn the user.
833836 StackHandler.warnOnStackNearlyExhausted (Ctx.PointOfInstantiation );
@@ -840,6 +843,11 @@ void Sema::popCodeSynthesisContext() {
840843 --NonInstantiationEntries;
841844 }
842845
846+ if (Active.Kind != CodeSynthesisContext::ConstraintSubstitution) {
847+ assert (NonConstraintSubstitutionEntries > 0 );
848+ --NonConstraintSubstitutionEntries;
849+ }
850+
843851 InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext ;
844852
845853 // Name lookup no longer looks in this template's defining module.
@@ -1363,13 +1371,6 @@ namespace {
13631371 bool BailOutOnIncomplete;
13641372
13651373 private:
1366- bool isSubstitutingConstraints () const {
1367- return llvm::any_of (SemaRef.CodeSynthesisContexts , [](auto &Context) {
1368- return Context.Kind ==
1369- Sema::CodeSynthesisContext::ConstraintSubstitution;
1370- });
1371- }
1372-
13731374 // CWG2770: Function parameters should be instantiated when they are
13741375 // needed by a satisfaction check of an atomic constraint or
13751376 // (recursively) by another function parameter.
@@ -1431,7 +1432,8 @@ namespace {
14311432 ArrayRef<UnexpandedParameterPack> Unexpanded,
14321433 bool &ShouldExpand, bool &RetainExpansion,
14331434 std::optional<unsigned > &NumExpansions) {
1434- if (SemaRef.CurrentInstantiationScope && isSubstitutingConstraints ()) {
1435+ if (SemaRef.CurrentInstantiationScope &&
1436+ SemaRef.inConstraintSubstitution ()) {
14351437 for (UnexpandedParameterPack ParmPack : Unexpanded) {
14361438 NamedDecl *VD = ParmPack.first .dyn_cast <NamedDecl *>();
14371439 if (!isa_and_present<ParmVarDecl>(VD))
@@ -1945,7 +1947,7 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
19451947 }
19461948
19471949 if (SemaRef.CurrentInstantiationScope ) {
1948- if (isSubstitutingConstraints () && isa<ParmVarDecl>(D) &&
1950+ if (SemaRef. inConstraintSubstitution () && isa<ParmVarDecl>(D) &&
19491951 maybeInstantiateFunctionParameterToScope (cast<ParmVarDecl>(D)))
19501952 return nullptr ;
19511953 }
0 commit comments