On Wed, Apr 25, 2012 at 5:36 PM, Rafael Espíndola <
[email protected]> 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.
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to