[cfe-commits] [patch] Error if a decl is redeclared with a different explicit visibility
Chandler Carruth
chandlerc at google.com
Wed Apr 25 17:44:49 PDT 2012
On Wed, Apr 25, 2012 at 5:36 PM, Rafael EspĂndola <
rafael.espindola at gmail.com> wrote:
> The attached patch makes clang produce an error for cases like
>
> struct __attribute__((visibility("hidden"))) a;
> struct __attribute__((visibility("default"))) b;
>
I assume you mean 'a' in that last line? ;] If so, yea, this looks fine.
However, regarding the patch:
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -1752,6 +1752,18 @@ static void handleVisibilityAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
return;
}
+ for (Decl::redecl_iterator I = D->redecls_begin(), E = D->redecls_end();
I != E; ++I) {
+ Decl *OldDecl = *I;
+ VisibilityAttr *OldAttr = OldDecl->getAttr<VisibilityAttr>();
+ if (!OldAttr)
+ continue;
+ VisibilityAttr::VisibilityType OldType = OldAttr->getVisibility();
+ if (OldType != type) {
+ S.Diag(Attr.getLoc(), diag::err_mismatched_visibilit);
+ S.Diag(OldAttr->getLocation(), diag::note_previous_attribute);
+ return;
+ }
+ }
We shouldn't loop over redeclarations here. We should simply have to
compare the current visibility with the visibility of the canonical
definition, error if different, and discard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120425/3fdba794/attachment.html>
More information about the cfe-commits
mailing list