From: Douglas Gregor Date: Fri, 28 Aug 2009 22:54:55 +0000 (+0000) Subject: Make sure we actually found a redeclaration before complaining about attributes added... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fdc39199c91e6246ac3f4da10eee96a369ce3e1a;p=clang Make sure we actually found a redeclaration before complaining about attributes added to a redeclaration in C++ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80403 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 85b5963a39..d1bb6fb453 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2736,7 +2736,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, ProcessDeclAttributes(S, NewFD, D); // attributes declared post-definition are currently ignored - if (PrevDecl) { + if (Redeclaration && PrevDecl) { const FunctionDecl *Def, *PrevFD = dyn_cast(PrevDecl); if (PrevFD && PrevFD->getBody(Def) && D.hasAttributes()) { Diag(NewFD->getLocation(), diag::warn_attribute_precede_definition); diff --git a/test/SemaCXX/attr-after-definition.cpp b/test/SemaCXX/attr-after-definition.cpp new file mode 100644 index 0000000000..2ef5acfbc0 --- /dev/null +++ b/test/SemaCXX/attr-after-definition.cpp @@ -0,0 +1,9 @@ +// RUN: clang-cc -fsyntax-only -verify %s +struct X { }; +struct Y { }; + +bool f0(X) { return true; } // expected-note{{definition}} +bool f1(X) { return true; } + +__attribute__ ((__visibility__("hidden"))) bool f0(X); // expected-warning{{attribute}} +__attribute__ ((__visibility__("hidden"))) bool f1(Y);