From: Rafael Espindola Date: Wed, 16 May 2012 02:10:38 +0000 (+0000) Subject: Fix the visibility of instantiations of static data members. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=797105a45a838a7c1cefd05dec3fd0cbaeb0a215;p=clang Fix the visibility of instantiations of static data members. Fixes pr12835. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156897 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 21405d223d..d31cf0f010 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -633,9 +633,19 @@ LinkageInfo NamedDecl::getLinkageAndVisibility() const { llvm::Optional NamedDecl::getExplicitVisibility() const { // Use the most recent declaration of a variable. - if (const VarDecl *var = dyn_cast(this)) - return getVisibilityOf(var->getMostRecentDecl()); + if (const VarDecl *Var = dyn_cast(this)) { + if (llvm::Optional V = + getVisibilityOf(Var->getMostRecentDecl())) + return V; + + if (Var->isStaticDataMember()) { + VarDecl *InstantiatedFrom = Var->getInstantiatedFromStaticDataMember(); + if (InstantiatedFrom) + return getVisibilityOf(InstantiatedFrom); + } + return llvm::Optional(); + } // Use the most recent declaration of a function, and also handle // function template specializations. if (const FunctionDecl *fn = dyn_cast(this)) { diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp index 9de9265db2..be8e199532 100644 --- a/test/CodeGenCXX/visibility.cpp +++ b/test/CodeGenCXX/visibility.cpp @@ -54,6 +54,18 @@ namespace test29 { // CHECK-HIDDEN: @_ZN6test299data_rectE = global } +namespace test40 { + template + struct foo { + DEFAULT static int bar; + }; + template + int foo::bar; + template struct foo; + // CHECK: _ZN6test403fooIiE3barE = weak_odr global + // CHECK-HIDDEN: _ZN6test403fooIiE3barE = weak_odr global +} + // CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10 // CHECK: @_ZN5Test71aE = hidden global // CHECK: @_ZN5Test71bE = global