From: Jakub Jelinek Date: Fri, 29 Jan 2016 11:14:42 +0000 (+0100) Subject: re PR debug/66869 (-Wunused-function no longer warns for static declarations without... X-Git-Tag: basepoints/gcc-7~1223 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=16b77b321eb72c5e2e1ec3628c035df80bef8534;p=thirdparty%2Fgcc.git re PR debug/66869 (-Wunused-function no longer warns for static declarations without definition) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6c66cc4747ac..3b5c9d505128 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-01-29 Jakub Jelinek + + PR debug/66869 + * decl.c (wrapup_globals_for_namespace): Warn about unused static + function declarations. + 2016-01-29 Marek Polacek PR c++/69509 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d8915fde2090..8da87d325b00 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 % but never defined", decl); + TREE_NO_WARNING (decl) = 1; + } + } + /* Write out any globals that need to be output. */ return wrapup_global_declarations (vec, len); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 866f0420f365..d021755eee7b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-01-29 Jakub Jelinek + + PR debug/66869 + * g++.dg/warn/Wunused-function2.C: New test. + 2016-01-29 Dominik Vogt * 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 index 000000000000..1b97df11bd3c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-function2.C @@ -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;