From: Hans Wennborg Date: Mon, 3 Nov 2014 16:09:16 +0000 (+0000) Subject: Don't allow dllimport/export on classes with internal linkage (PR21399) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d043706411e6068a4934d977803a6b35baa6f87;p=clang Don't allow dllimport/export on classes with internal linkage (PR21399) Trying to import or export such classes doesn't make sense, and Clang would assert trying to export vtables for them. This is consistent with how we treat functions with internal linkage, but it is stricter than MSVC so we may have to back down if it breaks real code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221160 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 031edf1515..0fae8c86d1 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4633,6 +4633,12 @@ static void checkDLLAttribute(Sema &S, CXXRecordDecl *Class) { if (!ClassAttr) return; + if (!Class->isExternallyVisible()) { + S.Diag(Class->getLocation(), diag::err_attribute_dll_not_extern) + << Class << ClassAttr; + return; + } + if (S.Context.getTargetInfo().getCXXABI().isMicrosoft() && !ClassAttr->isInherited()) { // Diagnose dll attributes on members of class with dll attribute. diff --git a/test/SemaCXX/dllexport.cpp b/test/SemaCXX/dllexport.cpp index e6fc91d6b9..5d002ac81e 100644 --- a/test/SemaCXX/dllexport.cpp +++ b/test/SemaCXX/dllexport.cpp @@ -327,6 +327,10 @@ template<> __declspec(dllexport) inline void funcTmpl template __declspec(dllimport) constexpr int CT // Classes //===----------------------------------------------------------------------===// +namespace { + struct __declspec(dllimport) AnonymousClass {}; // expected-error{{(anonymous namespace)::AnonymousClass' must have external linkage when declared 'dllimport'}} +} + class __declspec(dllimport) ClassDecl; class __declspec(dllimport) ClassDef { };