]> granicus.if.org Git - clang/commitdiff
Use the most recent redecl to decide if it is needed.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 26 Dec 2012 00:13:29 +0000 (00:13 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 26 Dec 2012 00:13:29 +0000 (00:13 +0000)
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

lib/Sema/Sema.cpp
test/SemaCXX/warn-func-not-needed.cpp [new file with mode: 0644]

index e195bbfff33675e0b1892a8d81fb68aee62e9261..e444f3c3570e6d56145c7a500530c0eb0ecd6658 100644 (file)
@@ -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<FunctionDecl>(D)) {
diff --git a/test/SemaCXX/warn-func-not-needed.cpp b/test/SemaCXX/warn-func-not-needed.cpp
new file mode 100644 (file)
index 0000000..437a428
--- /dev/null
@@ -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 <typename T>
+  void foo() {
+    f();
+  }
+}
+
+namespace test2 {
+  static void f() {}
+  static void f();
+  static void g() { f(); }
+  void h() { g(); }
+}