From cd95922bd1cd01c021fc4d517fa4b23edb488ae3 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Mon, 9 Jun 2014 18:30:28 +0000 Subject: [PATCH] Allow definition of dllimport static fields in partial specializations (PR19956) This expands the logic from r210141 to cover partial specializations too. llvm-svn: 210484 --- clang/lib/Sema/SemaDecl.cpp | 6 ++++-- clang/test/CodeGenCXX/dllimport.cpp | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ec0c27b2d2ed..09fcf1c8cbe4 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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(VD->getFirstDecl()->getDeclContext()); bool IsClassTemplateMember = - cast(VD->getFirstDecl()->getDeclContext()) - ->getDescribedClassTemplate(); + isa(Context) || + Context->getDescribedClassTemplate(); Diag(VD->getLocation(), IsClassTemplateMember diff --git a/clang/test/CodeGenCXX/dllimport.cpp b/clang/test/CodeGenCXX/dllimport.cpp index 0295943fdeaa..1c79c23ca815 100644 --- a/clang/test/CodeGenCXX/dllimport.cpp +++ b/clang/test/CodeGenCXX/dllimport.cpp @@ -581,12 +581,22 @@ namespace Vtordisp { } namespace ClassTemplateStaticDef { + // Regular template static field: template struct __declspec(dllimport) S { static int x; }; template int S::x; - // CHECK-DAG: @"\01?x@?$S@H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 + // MSC-DAG: @"\01?x@?$S@H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 int f() { return S::x; } + + // Partial class template specialization static field: + template struct T; + template struct __declspec(dllimport) T { + static int x; + }; + template int T::x; + // M32-DAG: @"\01?x@?$T@PAX@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 + int g() { return T::x; } } namespace PR19933 {