From: Rafael Espindola Date: Wed, 26 Dec 2012 00:13:29 +0000 (+0000) Subject: Use the most recent redecl to decide if it is needed. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=485458aa998c12e43bc9883b49060425d58b351d;p=clang Use the most recent redecl to decide if it is needed. This fixes pr14691, which I think is a regression from r168519. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171077 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index e195bbfff3..e444f3c357 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -328,7 +328,7 @@ CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) { /// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector. static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { - if (D->isUsed()) + if (D->getMostRecentDecl()->isUsed()) return true; if (const FunctionDecl *FD = dyn_cast(D)) { diff --git a/test/SemaCXX/warn-func-not-needed.cpp b/test/SemaCXX/warn-func-not-needed.cpp new file mode 100644 index 0000000000..437a428664 --- /dev/null +++ b/test/SemaCXX/warn-func-not-needed.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s + +namespace test1 { + static void f() {} // expected-warning {{is not needed and will not be emitted}} + static void f(); + template + void foo() { + f(); + } +} + +namespace test2 { + static void f() {} + static void f(); + static void g() { f(); } + void h() { g(); } +}