@@ -13657,12 +13657,16 @@ class Sema final : public SemaBase {
1365713657
1365813658 class LocalEagerInstantiationScope {
1365913659 public:
13660- LocalEagerInstantiationScope(Sema &S) : S(S) {
13660+ LocalEagerInstantiationScope(Sema &S, bool AtEndOfTU)
13661+ : S(S), AtEndOfTU(AtEndOfTU) {
1366113662 SavedPendingLocalImplicitInstantiations.swap(
1366213663 S.PendingLocalImplicitInstantiations);
1366313664 }
1366413665
13665- void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
13666+ void perform() {
13667+ S.PerformPendingInstantiations(/*LocalOnly=*/true,
13668+ /*AtEndOfTU=*/AtEndOfTU);
13669+ }
1366613670
1366713671 ~LocalEagerInstantiationScope() {
1366813672 assert(S.PendingLocalImplicitInstantiations.empty() &&
@@ -13673,6 +13677,7 @@ class Sema final : public SemaBase {
1367313677
1367413678 private:
1367513679 Sema &S;
13680+ bool AtEndOfTU;
1367613681 std::deque<PendingImplicitInstantiation>
1367713682 SavedPendingLocalImplicitInstantiations;
1367813683 };
@@ -13695,8 +13700,8 @@ class Sema final : public SemaBase {
1369513700
1369613701 class GlobalEagerInstantiationScope {
1369713702 public:
13698- GlobalEagerInstantiationScope(Sema &S, bool Enabled)
13699- : S(S), Enabled(Enabled) {
13703+ GlobalEagerInstantiationScope(Sema &S, bool Enabled, bool AtEndOfTU )
13704+ : S(S), Enabled(Enabled), AtEndOfTU(AtEndOfTU) {
1370013705 if (!Enabled)
1370113706 return;
1370213707
@@ -13710,7 +13715,8 @@ class Sema final : public SemaBase {
1371013715 void perform() {
1371113716 if (Enabled) {
1371213717 S.DefineUsedVTables();
13713- S.PerformPendingInstantiations();
13718+ S.PerformPendingInstantiations(/*LocalOnly=*/false,
13719+ /*AtEndOfTU=*/AtEndOfTU);
1371413720 }
1371513721 }
1371613722
@@ -13725,7 +13731,8 @@ class Sema final : public SemaBase {
1372513731 S.SavedVTableUses.pop_back();
1372613732
1372713733 // Restore the set of pending implicit instantiations.
13728- if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) {
13734+ if ((S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) &&
13735+ AtEndOfTU) {
1372913736 assert(S.PendingInstantiations.empty() &&
1373013737 "PendingInstantiations should be empty before it is discarded.");
1373113738 S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
@@ -13744,6 +13751,7 @@ class Sema final : public SemaBase {
1374413751 private:
1374513752 Sema &S;
1374613753 bool Enabled;
13754+ bool AtEndOfTU;
1374713755 };
1374813756
1374913757 ExplicitSpecifier instantiateExplicitSpecifier(
@@ -13929,7 +13937,8 @@ class Sema final : public SemaBase {
1392913937
1393013938 /// Performs template instantiation for all implicit template
1393113939 /// instantiations we have seen until this point.
13932- void PerformPendingInstantiations(bool LocalOnly = false);
13940+ void PerformPendingInstantiations(bool LocalOnly = false,
13941+ bool AtEndOfTU = true);
1393313942
1393413943 TemplateParameterList *
1393513944 SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
0 commit comments