From: Rafael Espindola Date: Tue, 1 May 2012 20:58:29 +0000 (+0000) Subject: Extend the error about incompatible visibility attributes in different X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e31b4d6cf25029aa280d691e9023359c0ef4204;p=clang Extend the error about incompatible visibility attributes in different decls to work on function templates specializations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155943 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 47e393c18d..c8af3a430a 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1752,7 +1752,13 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) { return; } - VisibilityAttr *PrevAttr = D->getCanonicalDecl()->getAttr(); + Decl *PrevDecl; + if (isa(D)) + PrevDecl = D->getMostRecentDecl()->getPreviousDecl(); + else + PrevDecl = D->getCanonicalDecl(); + + VisibilityAttr *PrevAttr = PrevDecl ? PrevDecl->getAttr() : 0; if (PrevAttr) { VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility(); if (PrevVisibility != type) { diff --git a/test/Sema/attr-visibility.c b/test/Sema/attr-visibility.c index afeb4f1546..499111f86c 100644 --- a/test/Sema/attr-visibility.c +++ b/test/Sema/attr-visibility.c @@ -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 index 0000000000..26dc67c6de --- /dev/null +++ b/test/SemaCXX/attr-visibility.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template +void foo() { +} +template <> + __attribute__((visibility("hidden"))) // expected-note {{previous attribute is here}} +void foo(); + +template <> +void foo(); + +template <> + __attribute__((visibility("default"))) // expected-error {{visibility does not match previous declaration}} +void foo() { +}