From: Hans Wennborg Date: Thu, 5 Oct 2017 21:45:27 +0000 (+0000) Subject: For dllexport class templates, export specializations of member functions (PR34849) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a389131d88ad4990b04d7bb1f03d46a72dbf597;p=clang For dllexport class templates, export specializations of member functions (PR34849) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315025 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 48fb2318e6..5b90557e79 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6041,6 +6041,21 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, diag::warn_dllimport_dropped_from_inline_function) << NewDecl << OldImportAttr; } + + // A specialization of a class template member function is processed here + // since it's a redeclaration. If the parent class is dllexport, the + // specialization inherits that attribute. This doesn't happen automatically + // since the parent class isn't instantiated until later. + if (IsSpecialization && isa(NewDecl) && !NewImportAttr && + !NewExportAttr) { + if (const DLLExportAttr *ParentExportAttr = cast(NewDecl) + ->getParent() + ->getAttr()) { + DLLExportAttr *NewAttr = ParentExportAttr->clone(S.Context); + NewAttr->setInherited(true); + NewDecl->addAttr(NewAttr); + } + } } /// Given that we are within the definition of the given function, diff --git a/test/CodeGenCXX/dllexport.cpp b/test/CodeGenCXX/dllexport.cpp index bdef2eb06e..a984b6d7ef 100644 --- a/test/CodeGenCXX/dllexport.cpp +++ b/test/CodeGenCXX/dllexport.cpp @@ -831,6 +831,14 @@ template struct ExplicitInstantiationTwoAttributes { void f() {} }; template struct __declspec(dllexport) __declspec(dllimport) ExplicitInstantiationTwoAttributes; // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitInstantiationTwoAttributes@H@@QAEXXZ" +// Specializations of exported class template functions get exported. +namespace pr34849 { +template struct __declspec(dllexport) ExportedClass { void foo(); }; +template<> void ExportedClass::foo() {} +template struct ExportedClass; +// M32-DAG: define dllexport x86_thiscallcc void @"\01?foo@?$ExportedClass@H@pr34849@@QAEXXZ" +} + //===----------------------------------------------------------------------===// // Classes with template base classes