diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 26b80f11fb48..e110a8cc8144 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -9239,10 +9239,18 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S, return (Decl*) nullptr; } - Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc()); if (Attr) ProcessDeclAttributeList(S, Specialization, Attr); + // In MSVC mode, dllimported explicit instantiation definitions are treated as + // instantiation declarations. + if (TSK == TSK_ExplicitInstantiationDefinition && + Specialization->hasAttr() && + Context.getTargetInfo().getCXXABI().isMicrosoft()) + TSK = TSK_ExplicitInstantiationDeclaration; + + Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc()); + if (Specialization->isDefined()) { // Let the ASTConsumer know that this function has been explicitly // instantiated now, and its linkage might have changed. diff --git a/clang/test/CodeGenCXX/dllimport.cpp b/clang/test/CodeGenCXX/dllimport.cpp index 372a96ba2efe..14558aec39a4 100644 --- a/clang/test/CodeGenCXX/dllimport.cpp +++ b/clang/test/CodeGenCXX/dllimport.cpp @@ -579,7 +579,7 @@ USE(inlineFuncTmpl) // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv() // GNU-DAG: define weak_odr void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv() -// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"() +// MO1-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"() // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() // GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv() // GO1-DAG: define weak_odr void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv() @@ -609,6 +609,15 @@ USE(funcTmpl) template<> __declspec(dllimport) inline void funcTmpl() {} USE(funcTmpl) +#ifdef MSABI +namespace pr35435 { +struct X; +template struct __declspec(dllimport) S { + void foo(T *t) { t->problem(); } +}; +template void S::foo(X*); // Cannot be instantiated because X is incomplete; dllimport means it's treated as an instantiation decl. +} +#endif //===----------------------------------------------------------------------===//