]> granicus.if.org Git - clang/commitdiff
Extend the error about incompatible visibility attributes in different
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 1 May 2012 20:58:29 +0000 (20:58 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 1 May 2012 20:58:29 +0000 (20:58 +0000)
decls to work on function templates specializations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155943 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-visibility.c
test/SemaCXX/attr-visibility.cpp [new file with mode: 0644]

index 47e393c18dda6689ea1df231ee0749a9e8a6fbc3..c8af3a430a2118204ccd6ee9c1809e5c7e6e5654 100644 (file)
@@ -1752,7 +1752,13 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
     return;
   }
 
-  VisibilityAttr *PrevAttr = D->getCanonicalDecl()->getAttr<VisibilityAttr>();
+  Decl *PrevDecl;
+  if (isa<FunctionDecl>(D))
+    PrevDecl = D->getMostRecentDecl()->getPreviousDecl();
+  else
+    PrevDecl = D->getCanonicalDecl();
+
+  VisibilityAttr *PrevAttr = PrevDecl ? PrevDecl->getAttr<VisibilityAttr>() : 0;
   if (PrevAttr) {
     VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility();
     if (PrevVisibility != type) {
index afeb4f1546f4081b2b5f6e8faa49dabe0f478151..499111f86ccdf3b59940c0a10478f6880d7f4525 100644 (file)
@@ -8,4 +8,5 @@ void test2() __attribute__((visibility("internal")));
 void test3() __attribute__((visibility("protected"))); // expected-warning {{target does not support 'protected' visibility; using 'default'}}
 
 struct __attribute__((visibility("hidden"))) test4; // expected-note {{previous attribute is here}}
+struct test4;
 struct __attribute__((visibility("default"))) test4; // expected-error {{visibility does not match previous declaration}}
diff --git a/test/SemaCXX/attr-visibility.cpp b/test/SemaCXX/attr-visibility.cpp
new file mode 100644 (file)
index 0000000..26dc67c
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <class Element>
+void foo() {
+}
+template <>
+ __attribute__((visibility("hidden")))  // expected-note {{previous attribute is here}}
+void foo<int>();
+
+template <>
+void foo<int>();
+
+template <>
+ __attribute__((visibility("default"))) // expected-error {{visibility does not match previous declaration}}
+void foo<int>() {
+}