From: Martin Storsjo Date: Fri, 26 Apr 2019 19:31:46 +0000 (+0000) Subject: [MinGW] Do dllexport inline methods in template instantiation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2061b0cab0002c264af632bf5e6ba5306c589c94;p=clang [MinGW] Do dllexport inline methods in template instantiation Normally, in MinGW mode, inline methods aren't dllexported. However, in the case of a dllimported template instantiation, the inline methods aren't instantiated locally, but referenced from the instantiation. Therefore, those methods also need to be dllexported, in the case of an instantiation. GCC suffers from the same issue, reported at [1], but the issue is still unresolved there. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89088 Differential Revision: https://reviews.llvm.org/D61176 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359343 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index c03bcb5e3a..2e7573d11e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5726,9 +5726,12 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl *Class) { continue; if (MD->isInlined()) { - // MinGW does not import or export inline methods. + // MinGW does not import or export inline methods. But do it for + // template instantiations. if (!Context.getTargetInfo().getCXXABI().isMicrosoft() && - !Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment()) + !Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment() && + TSK != TSK_ExplicitInstantiationDeclaration && + TSK != TSK_ExplicitInstantiationDefinition) continue; // MSVC versions before 2015 don't export the move assignment operators diff --git a/test/CodeGenCXX/mingw-template-dllexport.cpp b/test/CodeGenCXX/mingw-template-dllexport.cpp index 9e8f9b1bcc..408a3fd0a7 100644 --- a/test/CodeGenCXX/mingw-template-dllexport.cpp +++ b/test/CodeGenCXX/mingw-template-dllexport.cpp @@ -7,11 +7,9 @@ template class c { - void f(); + void f() {} }; -template void c::f() {} - template class __declspec(dllexport) c; // CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIiE1fEv