re PR debug/66869 (-Wunused-function no longer warns for static declarations without...
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Jan 2016 11:14:42 +0000 (12:14 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 29 Jan 2016 11:14:42 +0000 (12:14 +0100)
PR debug/66869
* decl.c (wrapup_globals_for_namespace): Warn about unused static
function declarations.

* g++.dg/warn/Wunused-function2.C: New test.

From-SVN: r232975

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-function2.C [new file with mode: 0644]

index 6c66cc4..3b5c9d5 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/66869
+       * decl.c (wrapup_globals_for_namespace): Warn about unused static
+       function declarations.
+
 2016-01-29  Marek Polacek  <polacek@redhat.com>
 
        PR c++/69509
index d8915fd..8da87d3 100644 (file)
@@ -879,6 +879,24 @@ wrapup_globals_for_namespace (tree name_space, void* data ATTRIBUTE_UNUSED)
   tree *vec = statics->address ();
   int len = statics->length ();
 
+  if (warn_unused_function)
+    {
+      tree decl;
+      unsigned int i;
+      FOR_EACH_VEC_SAFE_ELT (statics, i, decl)
+       if (TREE_CODE (decl) == FUNCTION_DECL
+           && DECL_INITIAL (decl) == 0
+           && DECL_EXTERNAL (decl)
+           && !TREE_PUBLIC (decl)
+           && !DECL_ARTIFICIAL (decl)
+           && !TREE_NO_WARNING (decl))
+         {
+           warning (OPT_Wunused_function,
+                    "%q+F declared %<static%> but never defined", decl);
+           TREE_NO_WARNING (decl) = 1;
+         }
+    }
+
   /* Write out any globals that need to be output.  */
   return wrapup_global_declarations (vec, len);
 }
index 866f042..d021755 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/66869
+       * g++.dg/warn/Wunused-function2.C: New test.
+
 2016-01-29  Dominik Vogt  <vogt@linux.vnet.ibm.com>
 
        * gcc.dg/tree-ssa/ssa-dom-cse-2.c: Require a hardware vector
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-function2.C b/gcc/testsuite/g++.dg/warn/Wunused-function2.C
new file mode 100644 (file)
index 0000000..1b97df1
--- /dev/null
@@ -0,0 +1,6 @@
+// PR debug/66869
+// { dg-do compile }
+// { dg-options "-Wunused-function" }
+
+static void test (void); // { dg-warning "'void test..' declared 'static' but never defined" }
+int i;