From 23458208b25acd7d2dfa003b029299e30124fe5f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 12 Jul 2012 20:05:04 +0000 Subject: [PATCH] Use the canonical template decl when trying to find if it has a visibility attribute. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160139 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 6 ++++-- test/CodeGenCXX/visibility.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 33826cbb46..2066a98984 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -702,8 +702,10 @@ llvm::Optional NamedDecl::getExplicitVisibility() const { // specialization of a class template, check for visibility // on the pattern. if (const ClassTemplateSpecializationDecl *spec - = dyn_cast(this)) - return getVisibilityOf(spec->getSpecializedTemplate()->getTemplatedDecl()); + = dyn_cast(this)) { + ClassTemplateDecl *TD = spec->getSpecializedTemplate()->getCanonicalDecl(); + return getVisibilityOf(TD->getTemplatedDecl()); + } // If this is a member class of a specialization of a class template // and the corresponding decl has explicit visibility, use that. diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp index 583293be52..94fb290ad1 100644 --- a/test/CodeGenCXX/visibility.cpp +++ b/test/CodeGenCXX/visibility.cpp @@ -1018,3 +1018,16 @@ namespace test54 { // CHECK: declare hidden void @_ZN6test543fooINS_3zedEE3barEv // CHECK-HIDDEN: declare hidden void @_ZN6test543fooINS_3zedEE3barEv } + +namespace test55 { + template + struct __attribute__((visibility("hidden"))) foo { + static void bar(); + }; + template struct foo; + void foobar() { + foo::bar(); + } + // CHECK: declare hidden void @_ZN6test553fooIiE3barEv + // CHECK-HIDDEN: declare hidden void @_ZN6test553fooIiE3barEv +}