Author: hans Date: Thu Oct 5 14:45:27 2017 New Revision: 315025 URL: http://llvm.org/viewvc/llvm-project?rev=315025&view=rev Log: For dllexport class templates, export specializations of member functions (PR34849)
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/test/CodeGenCXX/dllexport.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=315025&r1=315024&r2=315025&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 5 14:45:27 2017 @@ -6041,6 +6041,21 @@ static void checkDLLAttributeRedeclarati 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<CXXMethodDecl>(NewDecl) && !NewImportAttr && + !NewExportAttr) { + if (const DLLExportAttr *ParentExportAttr = cast<CXXMethodDecl>(NewDecl) + ->getParent() + ->getAttr<DLLExportAttr>()) { + DLLExportAttr *NewAttr = ParentExportAttr->clone(S.Context); + NewAttr->setInherited(true); + NewDecl->addAttr(NewAttr); + } + } } /// Given that we are within the definition of the given function, Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=315025&r1=315024&r2=315025&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original) +++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Thu Oct 5 14:45:27 2017 @@ -831,6 +831,14 @@ template <typename T> struct ExplicitIns template struct __declspec(dllexport) __declspec(dllimport) ExplicitInstantiationTwoAttributes<int>; // 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 <typename T> struct __declspec(dllexport) ExportedClass { void foo(); }; +template<> void ExportedClass<int>::foo() {} +template struct ExportedClass<int>; +// M32-DAG: define dllexport x86_thiscallcc void @"\01?foo@?$ExportedClass@H@pr34849@@QAEXXZ" +} + //===----------------------------------------------------------------------===// // Classes with template base classes _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits