diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b107e8bd2a39..3d0d1e666cd4 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -9724,6 +9724,14 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { cast(D)->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; + // Implicit member function definitions, such as operator= might not be + // marked as template specializations, since they're not coming from a + // template but synthesized directly on the class. + IsExpInstDef |= + isa(D) && + cast(D)->getParent()->getTemplateSpecializationKind() == + TSK_ExplicitInstantiationDefinition; + if (getExternalSource()->DeclIsFromPCHWithObjectFile(D) && !IsExpInstDef) return false; } diff --git a/clang/test/CodeGen/pch-dllexport.cpp b/clang/test/CodeGen/pch-dllexport.cpp index 9c6623be4362..b8db075046de 100644 --- a/clang/test/CodeGen/pch-dllexport.cpp +++ b/clang/test/CodeGen/pch-dllexport.cpp @@ -57,6 +57,13 @@ extern template void explicitInstantiationDefAfterDecl(int); template T __declspec(dllexport) variableTemplate; extern template int variableTemplate; +namespace pr38934 { +template struct S {}; +extern template struct S; +// The use here causes the S::operator= decl to go into the PCH. +inline void use(S *a, S *b) { *a = *b; }; +} + #else void use() { @@ -81,4 +88,9 @@ template void __declspec(dllexport) explicitInstantiationDefAfterDecl(int); template int __declspec(dllexport) variableTemplate; // PCHWITHOBJVARS: @"??$variableTemplate@H@@3HA" = weak_odr dso_local dllexport global +// PR38934: Make sure S::operator= gets emitted. While it itself isn't a +// template specialization, its parent is. +template struct __declspec(dllexport) pr38934::S; +// PCHWITHOBJ: define weak_odr dso_local dllexport x86_thiscallcc dereferenceable(1) %"struct.pr38934::S"* @"??4?$S@H@pr38934@@QAEAAU01@ABU01@@Z" + #endif