]> granicus.if.org Git - clang/commitdiff
Fix a bug in my previous commit. The problem is not that we were not using the
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 13 Jul 2012 01:19:08 +0000 (01:19 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 13 Jul 2012 01:19:08 +0000 (01:19 +0000)
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

lib/AST/Decl.cpp
lib/Sema/SemaTemplate.cpp
test/CodeGenCXX/visibility.cpp

index 2066a98984cd1afd842a9fd8d920b6cf7c851cd6..33826cbb466d91e4c3ce9df39452239322e161ab 100644 (file)
@@ -702,10 +702,8 @@ llvm::Optional<Visibility> NamedDecl::getExplicitVisibility() const {
   // specialization of a class template, check for visibility
   // on the pattern.
   if (const ClassTemplateSpecializationDecl *spec
-      = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
-    ClassTemplateDecl *TD = spec->getSpecializedTemplate()->getCanonicalDecl();
-    return getVisibilityOf(TD->getTemplatedDecl());
-  }
+        = dyn_cast<ClassTemplateSpecializationDecl>(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.
index 4605e01fa25433a3bcd8e5b23ac302e8260d57e7..5d14d8762c55f9773efbac449eac8340edd67cf8 100644 (file)
@@ -1134,6 +1134,9 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
     NewTemplate->setInvalidDecl();
     NewClass->setInvalidDecl();
   }
+  if (PrevClassTemplate)
+    mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl());
+
   return NewTemplate;
 }
 
index 94fb290ad1c3d9b877b3b688b70ad3899e931e31..92b7f4453fe001b40e637a926f0992daf5e31768 100644 (file)
@@ -1031,3 +1031,16 @@ namespace test55 {
   // CHECK: declare hidden void @_ZN6test553fooIiE3barEv
   // CHECK-HIDDEN: declare hidden void @_ZN6test553fooIiE3barEv
 }
+
+namespace test56 {
+  template <class T> struct foo;
+  template <class T>
+  struct __attribute__((visibility("hidden"))) foo {
+    static void bar();
+  };
+  void foobar() {
+    foo<int>::bar();
+  }
+  // CHECK: declare hidden void @_ZN6test563fooIiE3barEv
+  // CHECK-HIDDEN: declare hidden void @_ZN6test563fooIiE3barEv
+}