From: Rafael Espindola Date: Fri, 13 Jul 2012 01:19:08 +0000 (+0000) Subject: Fix a bug in my previous commit. The problem is not that we were not using the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3d02dd0ae17eabc8e0b8972ac6a3863534b39d2;p=clang Fix a bug in my previous commit. The problem is not that we were not using the canonical decl for the template, but that we were not merging attributes for templates at all! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 2066a98984..33826cbb46 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -702,10 +702,8 @@ llvm::Optional NamedDecl::getExplicitVisibility() const { // specialization of a class template, check for visibility // on the pattern. if (const ClassTemplateSpecializationDecl *spec - = dyn_cast(this)) { - ClassTemplateDecl *TD = spec->getSpecializedTemplate()->getCanonicalDecl(); - return getVisibilityOf(TD->getTemplatedDecl()); - } + = dyn_cast(this)) + return getVisibilityOf(spec->getSpecializedTemplate()->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/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 4605e01fa2..5d14d8762c 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1134,6 +1134,9 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, NewTemplate->setInvalidDecl(); NewClass->setInvalidDecl(); } + if (PrevClassTemplate) + mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl()); + return NewTemplate; } diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp index 94fb290ad1..92b7f4453f 100644 --- a/test/CodeGenCXX/visibility.cpp +++ b/test/CodeGenCXX/visibility.cpp @@ -1031,3 +1031,16 @@ namespace test55 { // CHECK: declare hidden void @_ZN6test553fooIiE3barEv // CHECK-HIDDEN: declare hidden void @_ZN6test553fooIiE3barEv } + +namespace test56 { + template struct foo; + template + struct __attribute__((visibility("hidden"))) foo { + static void bar(); + }; + void foobar() { + foo::bar(); + } + // CHECK: declare hidden void @_ZN6test563fooIiE3barEv + // CHECK-HIDDEN: declare hidden void @_ZN6test563fooIiE3barEv +}