r210484 - Allow definition of dllimport static fields in partial specializations (PR19956)

Hans Wennborg hans at hanshq.net
Mon Jun 9 11:30:29 PDT 2014


Author: hans
Date: Mon Jun  9 13:30:28 2014
New Revision: 210484

URL: http://llvm.org/viewvc/llvm-project?rev=210484&view=rev
Log:
Allow definition of dllimport static fields in partial specializations (PR19956)

This expands the logic from r210141 to cover partial specializations too.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGenCXX/dllimport.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=210484&r1=210483&r2=210484&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jun  9 13:30:28 2014
@@ -9111,9 +9111,11 @@ Sema::FinalizeDeclaration(Decl *ThisDecl
         VD->isThisDeclarationADefinition()) {
       // We allow definitions of dllimport class template static data members
       // with a warning.
+      CXXRecordDecl *Context =
+        cast<CXXRecordDecl>(VD->getFirstDecl()->getDeclContext());
       bool IsClassTemplateMember =
-          cast<CXXRecordDecl>(VD->getFirstDecl()->getDeclContext())
-              ->getDescribedClassTemplate();
+          isa<ClassTemplatePartialSpecializationDecl>(Context) ||
+          Context->getDescribedClassTemplate();
 
       Diag(VD->getLocation(),
            IsClassTemplateMember

Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=210484&r1=210483&r2=210484&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Mon Jun  9 13:30:28 2014
@@ -581,12 +581,22 @@ namespace Vtordisp {
 }
 
 namespace ClassTemplateStaticDef {
+  // Regular template static field:
   template <typename T> struct __declspec(dllimport) S {
     static int x;
   };
   template <typename T> int S<T>::x;
-  // CHECK-DAG: @"\01?x@?$S at H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0
+  // MSC-DAG: @"\01?x@?$S at H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0
   int f() { return S<int>::x; }
+
+  // Partial class template specialization static field:
+  template <typename A> struct T;
+  template <typename A> struct __declspec(dllimport) T<A*> {
+    static int x;
+  };
+  template <typename A> int T<A*>::x;
+  // M32-DAG: @"\01?x@?$T at PAX@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0
+  int g() { return T<void*>::x; }
 }
 
 namespace PR19933 {





More information about the cfe-commits mailing list