Avoid producing implicit methods when we have a explicit template instantiation
declaration.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99311 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index 9204e4e..cedefba 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -3805,7 +3805,17 @@
return;
TemplateSpecializationKind kind = RD->getTemplateSpecializationKind();
- if (kind == TSK_ImplicitInstantiation)
+
+
+ // The reason we have TSK_ExplicitInstantiationDeclaration in here (but not
+ // in Sema::MaybeMarkVirtualMembersReferenced) is for the case
+ // template<> void stdio_sync_filebuf<wchar_t>::xsgetn() {
+ // }
+ // extern template class stdio_sync_filebuf<wchar_t>;
+ // Since we are called after the extern declaration is seen.
+
+ if (kind == TSK_ImplicitInstantiation ||
+ kind == TSK_ExplicitInstantiationDeclaration)
CGM.DeferredVtables.push_back(RD);
else
GenerateClassData(CGM.getVtableLinkage(RD), RD);
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 1606710..69ce49c 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -310,8 +310,17 @@
// instantiated when used so that the body can be considered for
// inlining, but that no out-of-line copy of the inline function would be
// generated in the translation unit. -- end note ]
- if (FD->getTemplateSpecializationKind()
- == TSK_ExplicitInstantiationDeclaration)
+
+ // We check the specialization kind of the class for implicit methods.
+ // They have a TSK_Undeclared specialization kind.
+ TemplateSpecializationKind TSK;
+ const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
+ if (MD && MD->isImplicit())
+ TSK = MD->getParent()->getTemplateSpecializationKind();
+ else
+ TSK = FD->getTemplateSpecializationKind();
+
+ if (TSK == TSK_ExplicitInstantiationDeclaration)
return CodeGenModule::GVA_C99Inline;
return CodeGenModule::GVA_CXXInline;