Keep track of whether a member function instantiated from a member
function of a class template was implicitly instantiated, explicitly
instantiated (declaration or definition), or explicitly
specialized. The same MemberSpecializationInfo structure will be used
for static data members and member classes as well.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83509 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index f3cd2e4..339a084 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -3171,10 +3171,13 @@
Instantiation, FD->getLocation(),
false, TSK_ExplicitSpecialization))
return true;
+
+ // FIXME: Check for specialization-after-instantiation errors and such.
- // FIXME: Mark the new declaration as a member function specialization.
- // We may also want to mark the original instantiation as having been
- // explicitly specialized.
+ // Note that this function is an explicit instantiation of a member function.
+ Instantiation->setTemplateSpecializationKind(TSK_ExplicitSpecialization);
+ FD->setInstantiationOfMemberFunction(FunctionInTemplate,
+ TSK_ExplicitSpecialization);
// Save the caller the trouble of having to figure out which declaration
// this specialization matches.
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 9c96b33..e0ffca9 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -977,6 +977,8 @@
DEnd = Instantiation->decls_end();
D != DEnd; ++D) {
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) {
+ if (Function->getInstantiatedFromMemberFunction())
+ Function->setTemplateSpecializationKind(TSK);
if (!Function->getBody() && TSK != TSK_ExplicitInstantiationDeclaration)
InstantiateFunctionDefinition(PointOfInstantiation, Function);
} else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) {
@@ -984,14 +986,19 @@
TSK != TSK_ExplicitInstantiationDeclaration)
InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var);
} else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) {
- if (!Record->isInjectedClassName() && !Record->getDefinition(Context)) {
- assert(Record->getInstantiatedFromMemberClass() &&
- "Missing instantiated-from-template information");
+ if (Record->isInjectedClassName())
+ continue;
+
+ assert(Record->getInstantiatedFromMemberClass() &&
+ "Missing instantiated-from-template information");
+ if (!Record->getDefinition(Context))
InstantiateClass(PointOfInstantiation, Record,
Record->getInstantiatedFromMemberClass(),
TemplateArgs,
TSK);
- }
+ else
+ InstantiateClassMembers(PointOfInstantiation, Record, TemplateArgs,
+ TSK);
}
}
}
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index fa30365..fcacb4a 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -522,7 +522,7 @@
if (!Owner->isDependentContext())
DC->makeDeclVisibleInContext(Function, /* Recoverable = */ false);
- Function->setInstantiationOfMemberFunction(D);
+ Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
}
if (InitFunctionInstantiation(Function, D))
@@ -637,7 +637,7 @@
FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext());
Method->setDescribedFunctionTemplate(FunctionTemplate);
} else if (!FunctionTemplate)
- Method->setInstantiationOfMemberFunction(D);
+ Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
// If we are instantiating a member function defined
// out-of-line, the instantiation will have the same lexical