diff options
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/attr-after-definition.cpp | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 85b5963a39d..d1bb6fb453e 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<FunctionDecl>(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 00000000000..2ef5acfbc0f --- /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); |