]> granicus.if.org Git - clang/commitdiff
[MinGW] Do dllexport inline methods in template instantiation
authorMartin Storsjo <martin@martin.st>
Fri, 26 Apr 2019 19:31:46 +0000 (19:31 +0000)
committerMartin Storsjo <martin@martin.st>
Fri, 26 Apr 2019 19:31:46 +0000 (19:31 +0000)
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

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/mingw-template-dllexport.cpp

index c03bcb5e3a5b2c4ad6276a4ae48c9785bfad42c3..2e7573d11ef75c68ef99b9538f9cd05bf3555593 100644 (file)
@@ -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
index 9e8f9b1bccff9c85144e4506f67c7878da245016..408a3fd0a77ddac051d6ae7e0710585a079cbe71 100644 (file)
@@ -7,11 +7,9 @@
 
 template <class T>
 class c {
-  void f();
+  void f() {}
 };
 
-template <class T> void c<T>::f() {}
-
 template class __declspec(dllexport) c<int>;
 
 // CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIiE1fEv