From: Rafael Espindola Date: Thu, 12 Jul 2012 04:32:30 +0000 (+0000) Subject: Ignore visibility attributes after definitions. This matches newer (4.7) gcc's X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f729ce0b231e045b8e7db61e85e87186c09db238;p=clang Ignore visibility attributes after definitions. This matches newer (4.7) gcc's behavior and is the first step in fixing pr13338. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160104 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ebbdb8b263..769285a0b8 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1637,6 +1637,9 @@ def err_attribute_aligned_greater_than_8192 : Error< def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning< "'%0' redeclared without %1 attribute: previous %1 ignored">; def warn_attribute_ignored : Warning<"%0 attribute ignored">; +def warn_attribute_after_definition_ignored : Warning< + "attribute %0 after definition is ignored">, + InGroup; def warn_unknown_attribute_ignored : Warning< "unknown attribute %0 ignored">, InGroup; def warn_unhandled_ms_attribute_ignored : Warning< diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index ebd9180ec6..ba1b4f77fc 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4700,6 +4700,14 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, AdjustDeclIfTemplate(TagDecl); + for (const AttributeList* l = AttrList; l; l = l->getNext()) { + if (l->getKind() != AttributeList::AT_Visibility) + continue; + l->setInvalid(); + Diag(l->getLoc(), diag::warn_attribute_after_definition_ignored) << + l->getName(); + } + ActOnFields(S, RLoc, TagDecl, llvm::makeArrayRef( // strict aliasing violation! reinterpret_cast(FieldCollector->getCurFields()), diff --git a/test/CodeGenCXX/pragma-visibility.cpp b/test/CodeGenCXX/pragma-visibility.cpp index e54626ee2e..9b54a1813c 100644 --- a/test/CodeGenCXX/pragma-visibility.cpp +++ b/test/CodeGenCXX/pragma-visibility.cpp @@ -16,14 +16,6 @@ int x2::y = 10; // CHECK: @_ZN2x21yE = global #pragma GCC visibility pop -#pragma GCC visibility push(hidden) -struct x3 { - static int y; -} __attribute((visibility("default"))); -int x3::y = 10; -// CHECK: @_ZN2x31yE = global -#pragma GCC visibility pop - #pragma GCC visibility push(hidden) template struct x4 { static int y; diff --git a/test/SemaCXX/attr-visibility.cpp b/test/SemaCXX/attr-visibility.cpp index 26dc67c6de..05aa5a33c7 100644 --- a/test/SemaCXX/attr-visibility.cpp +++ b/test/SemaCXX/attr-visibility.cpp @@ -14,3 +14,7 @@ template <> __attribute__((visibility("default"))) // expected-error {{visibility does not match previous declaration}} void foo() { } + +struct x3 { + static int y; +} __attribute((visibility("default"))); // expected-warning {{attribute 'visibility' after definition is ignored}}