]> granicus.if.org Git - clang/commitdiff
Make sure we actually found a redeclaration before complaining about attributes added...
authorDouglas Gregor <dgregor@apple.com>
Fri, 28 Aug 2009 22:54:55 +0000 (22:54 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 28 Aug 2009 22:54:55 +0000 (22:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80403 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/attr-after-definition.cpp [new file with mode: 0644]

index 85b5963a39d91c4c9431e4aa63dae030dbfcf9fd..d1bb6fb453e592ab2b266560b650e7fcdd19b516 100644 (file)
@@ -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/test/SemaCXX/attr-after-definition.cpp b/test/SemaCXX/attr-after-definition.cpp
new file mode 100644 (file)
index 0000000..2ef5acf
--- /dev/null
@@ -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);