diff options
author | Mark Wielaard <mjw@redhat.com> | 2016-02-22 22:42:19 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2016-02-22 22:42:19 +0000 |
commit | 4246c8da675115145c206b475b2a224269bfd228 (patch) | |
tree | ca99c93ee8a42bd45375966c5fac2b44cca0e3f8 /gcc/cgraphunit.c | |
parent | 07bfc9c103a685d5ad59ce846188c449e81055df (diff) | |
download | gcc-4246c8da675115145c206b475b2a224269bfd228.zip gcc-4246c8da675115145c206b475b2a224269bfd228.tar.gz gcc-4246c8da675115145c206b475b2a224269bfd228.tar.bz2 |
PR28901 Add two levels for -Wunused-const-variable.
There is some controversy about enabling -Wunused-const-variable for all
unused static const variables because some feel there are too many errors
exposed in header files. Create two levels for -Wunused-const-variable.
One level to only check for unused static const variables in the main
compilation file. Which is enabled by -Wunused-variable. And a second
level that also checks for unused static const variables in included
files. Which must be explicitly enabled.
gcc/ChangeLog
PR c/28901
* cgraphunit.c (check_global_declaration): Check level of
warn_unused_const_variable and main_input_filename.
* doc/invoke.texi (Warning Options): Add -Wunused-const-variable=.
(-Wunused-variable): For C implies -Wunused-const-variable=1.
(-Wunused-const-variable): Explain levels 1 and 2.
gcc/c-family/ChangeLog
PR c/28901
* c.opt (Wunused-const-variable): Turn into Alias for...
(Wunused-const-variable=): New option.
gcc/testsuite/ChangeLog
PR c/28901
* gcc.dg/unused-variable-3.c: New test.
From-SVN: r233616
Diffstat (limited to 'gcc/cgraphunit.c')
-rw-r--r-- | gcc/cgraphunit.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 0a745f0..27a073a 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -942,7 +942,10 @@ check_global_declaration (symtab_node *snode) /* Warn about static fns or vars defined but not used. */ if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL) || (((warn_unused_variable && ! TREE_READONLY (decl)) - || (warn_unused_const_variable && TREE_READONLY (decl))) + || (warn_unused_const_variable > 0 && TREE_READONLY (decl) + && (warn_unused_const_variable == 2 + || filename_cmp (main_input_filename, + DECL_SOURCE_FILE (decl)) == 0))) && TREE_CODE (decl) == VAR_DECL)) && ! DECL_IN_SYSTEM_HEADER (decl) && ! snode->referred_to_p (/*include_self=*/false) @@ -971,7 +974,7 @@ check_global_declaration (symtab_node *snode) (TREE_CODE (decl) == FUNCTION_DECL) ? OPT_Wunused_function : (TREE_READONLY (decl) - ? OPT_Wunused_const_variable + ? OPT_Wunused_const_variable_ : OPT_Wunused_variable), "%qD defined but not used", decl); } |