@@ -2362,7 +2362,8 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
2362
2362
// DR1484 clarifies that the members of a local class are instantiated as part
2363
2363
// of the instantiation of their enclosing entity.
2364
2364
if (D->isCompleteDefinition () && D->isLocalClass ()) {
2365
- Sema::LocalEagerInstantiationScope LocalInstantiations (SemaRef);
2365
+ Sema::LocalEagerInstantiationScope LocalInstantiations (SemaRef,
2366
+ /* AtEndOfTU=*/ false );
2366
2367
2367
2368
SemaRef.InstantiateClass (D->getLocation (), Record, D, TemplateArgs,
2368
2369
TSK_ImplicitInstantiation,
@@ -5344,8 +5345,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
5344
5345
// This has to happen before LateTemplateParser below is called, so that
5345
5346
// it marks vtables used in late parsed templates as used.
5346
5347
GlobalEagerInstantiationScope GlobalInstantiations (*this ,
5347
- /* Enabled=*/ Recursive);
5348
- LocalEagerInstantiationScope LocalInstantiations (*this );
5348
+ /* Enabled=*/ Recursive,
5349
+ /* AtEndOfTU=*/ AtEndOfTU);
5350
+ LocalEagerInstantiationScope LocalInstantiations (*this ,
5351
+ /* AtEndOfTU=*/ AtEndOfTU);
5349
5352
5350
5353
// Call the LateTemplateParser callback if there is a need to late parse
5351
5354
// a templated function definition.
@@ -5919,10 +5922,12 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
5919
5922
// If we're performing recursive template instantiation, create our own
5920
5923
// queue of pending implicit instantiations that we will instantiate
5921
5924
// later, while we're still within our own instantiation context.
5922
- GlobalEagerInstantiationScope GlobalInstantiations (*this ,
5923
- /* Enabled=*/ Recursive);
5925
+ GlobalEagerInstantiationScope GlobalInstantiations (
5926
+ *this ,
5927
+ /* Enabled=*/ Recursive, /* AtEndOfTU=*/ AtEndOfTU);
5924
5928
LocalInstantiationScope Local (*this );
5925
- LocalEagerInstantiationScope LocalInstantiations (*this );
5929
+ LocalEagerInstantiationScope LocalInstantiations (*this ,
5930
+ /* AtEndOfTU=*/ AtEndOfTU);
5926
5931
5927
5932
// Enter the scope of this instantiation. We don't use
5928
5933
// PushDeclContext because we don't have a scope.
@@ -6019,14 +6024,16 @@ void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
6019
6024
// queue of pending implicit instantiations that we will instantiate later,
6020
6025
// while we're still within our own instantiation context.
6021
6026
GlobalEagerInstantiationScope GlobalInstantiations (*this ,
6022
- /* Enabled=*/ Recursive);
6027
+ /* Enabled=*/ Recursive,
6028
+ /* AtEndOfTU=*/ AtEndOfTU);
6023
6029
6024
6030
// Enter the scope of this instantiation. We don't use
6025
6031
// PushDeclContext because we don't have a scope.
6026
6032
ContextRAII PreviousContext (*this , Var->getDeclContext ());
6027
6033
LocalInstantiationScope Local (*this );
6028
6034
6029
- LocalEagerInstantiationScope LocalInstantiations (*this );
6035
+ LocalEagerInstantiationScope LocalInstantiations (*this ,
6036
+ /* AtEndOfTU=*/ AtEndOfTU);
6030
6037
6031
6038
VarDecl *OldVar = Var;
6032
6039
if (Def->isStaticDataMember () && !Def->isOutOfLine ()) {
@@ -6774,18 +6781,20 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
6774
6781
return D;
6775
6782
}
6776
6783
6777
- void Sema::PerformPendingInstantiations (bool LocalOnly) {
6778
- std::deque<PendingImplicitInstantiation> delayedPCHInstantiations ;
6784
+ void Sema::PerformPendingInstantiations (bool LocalOnly, bool AtEndOfTU ) {
6785
+ std::deque<PendingImplicitInstantiation> DelayedImplicitInstantiations ;
6779
6786
while (!PendingLocalImplicitInstantiations.empty () ||
6780
6787
(!LocalOnly && !PendingInstantiations.empty ())) {
6781
6788
PendingImplicitInstantiation Inst;
6782
6789
6790
+ bool LocalInstantiation = false ;
6783
6791
if (PendingLocalImplicitInstantiations.empty ()) {
6784
6792
Inst = PendingInstantiations.front ();
6785
6793
PendingInstantiations.pop_front ();
6786
6794
} else {
6787
6795
Inst = PendingLocalImplicitInstantiations.front ();
6788
6796
PendingLocalImplicitInstantiations.pop_front ();
6797
+ LocalInstantiation = true ;
6789
6798
}
6790
6799
6791
6800
// Instantiate function definitions
@@ -6794,22 +6803,26 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
6794
6803
TSK_ExplicitInstantiationDefinition;
6795
6804
if (Function->isMultiVersion ()) {
6796
6805
getASTContext ().forEachMultiversionedFunctionVersion (
6797
- Function, [this , Inst, DefinitionRequired](FunctionDecl *CurFD) {
6806
+ Function,
6807
+ [this , Inst, DefinitionRequired, AtEndOfTU](FunctionDecl *CurFD) {
6798
6808
InstantiateFunctionDefinition (/* FIXME:*/ Inst.second , CurFD, true ,
6799
- DefinitionRequired, true );
6809
+ DefinitionRequired, AtEndOfTU );
6800
6810
if (CurFD->isDefined ())
6801
6811
CurFD->setInstantiationIsPending (false );
6802
6812
});
6803
6813
} else {
6804
6814
InstantiateFunctionDefinition (/* FIXME:*/ Inst.second , Function, true ,
6805
- DefinitionRequired, true );
6815
+ DefinitionRequired, AtEndOfTU );
6806
6816
if (Function->isDefined ())
6807
6817
Function->setInstantiationIsPending (false );
6808
6818
}
6809
6819
// Definition of a PCH-ed template declaration may be available only in the TU.
6810
6820
if (!LocalOnly && LangOpts.PCHInstantiateTemplates &&
6811
6821
TUKind == TU_Prefix && Function->instantiationIsPending ())
6812
- delayedPCHInstantiations.push_back (Inst);
6822
+ DelayedImplicitInstantiations.push_back (Inst);
6823
+ else if (!AtEndOfTU && Function->instantiationIsPending () &&
6824
+ !LocalInstantiation)
6825
+ DelayedImplicitInstantiations.push_back (Inst);
6813
6826
continue ;
6814
6827
}
6815
6828
@@ -6853,11 +6866,11 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
6853
6866
// Instantiate static data member definitions or variable template
6854
6867
// specializations.
6855
6868
InstantiateVariableDefinition (/* FIXME:*/ Inst.second , Var, true ,
6856
- DefinitionRequired, true );
6869
+ DefinitionRequired, AtEndOfTU );
6857
6870
}
6858
6871
6859
- if (!LocalOnly && LangOpts. PCHInstantiateTemplates )
6860
- PendingInstantiations.swap (delayedPCHInstantiations );
6872
+ if (!DelayedImplicitInstantiations. empty () )
6873
+ PendingInstantiations.swap (DelayedImplicitInstantiations );
6861
6874
}
6862
6875
6863
6876
void Sema::PerformDependentDiagnostics (const DeclContext *Pattern,
0 commit comments