]> granicus.if.org Git - clang/commitdiff
Don't allow dllimport/export on classes with internal linkage (PR21399)
authorHans Wennborg <hans@hanshq.net>
Mon, 3 Nov 2014 16:09:16 +0000 (16:09 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 3 Nov 2014 16:09:16 +0000 (16:09 +0000)
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

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/dllexport.cpp
test/SemaCXX/dllimport.cpp

index 031edf1515b38f9375048ba74f92abe43c6c1614..0fae8c86d1b275a48720234c7022c085a588eab7 100644 (file)
@@ -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.
index e6fc91d6b94614c116710d30a56c67bd65a04e5e..5d002ac81e5c6ee69fdd0ced3dd399e9ca291da9 100644 (file)
@@ -327,6 +327,10 @@ template<> __declspec(dllexport) inline void funcTmpl<ExplicitSpec_InlineDef_Exp
 // Classes
 //===----------------------------------------------------------------------===//
 
+namespace {
+  struct __declspec(dllexport) AnonymousClass {}; // expected-error{{(anonymous namespace)::AnonymousClass' must have external linkage when declared 'dllexport'}}
+}
+
 class __declspec(dllexport) ClassDecl;
 
 class __declspec(dllexport) ClassDef {};
index 50d952e3a89f8fb3b9ef50914e160612b816df4c..eb6a554522ba93613337be7f2f6fa6b8224d7b68 100644 (file)
@@ -1197,6 +1197,10 @@ template<typename T> template<typename U> __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 { };