From 90820ee62a9217e6da4ee0a7e1ae768ab3bcade3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 28 Aug 2009 22:54:55 +0000 Subject: [PATCH] Make sure we actually found a redeclaration before complaining about attributes added to a redeclaration in C++ llvm-svn: 80403 --- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/test/SemaCXX/attr-after-definition.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/attr-after-definition.cpp diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 85b5963a39d9..d1bb6fb453e5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/test/SemaCXX/attr-after-definition.cpp b/clang/test/SemaCXX/attr-after-definition.cpp new file mode 100644 index 000000000000..2ef5acfbc0f1 --- /dev/null +++ b/clang/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);