]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/c-family/ChangeLog
PR28901 -Wunused-variable ignores unused const initialised variables in C
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 14 Sep 2015 09:49:47 +0000 (09:49 +0000)
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 14 Sep 2015 09:49:47 +0000 (09:49 +0000)
commit1bca8cbd0c68366f07277f98ce6963e10c2aa617
tree69691ab92ba1ad50826f35684fac28f7495db523
parenta6b9137e4b11feb3150ae0addf5533755201d210
PR28901 -Wunused-variable ignores unused const initialised variables in C

12 years ago it was decided that -Wunused-variable shouldn't warn about
static const variables because some code used const static char rcsid[]
strings which were never used but wanted in the code anyway. But as the
bug points out this hides some real bugs. These days the usage of rcsids
is not very popular anymore. So this patch changes the default to warn
about unused static const variables in C with -Wunused-variable. And it
adds a new option -Wno-unused-const-variable to turn this warning off.
For C++ this new warning is off by default, since const variables can be
used as #defines in C++. New testcases for the new defaults in C and C++
are included testing the new warning and suppressing it with an unused
attribute or using -Wno-unused-const-variable.

gcc/ChangeLog

       PR c/28901
       * toplev.c (check_global_declaration): Check and use
       warn_unused_const_variable.
       * doc/invoke.texi (Warning Options): Add -Wunused-const-variable.
       (-Wunused-variable): Remove non-constant. For C implies
       -Wunused-const-variable.
       (-Wunused-const-variable): New.

gcc/c-family/ChangeLog

       PR c/28901
       * c.opt (Wunused-variable): Option from common.opt.
       (Wunused-const-variable): New option.

gcc/cp/ChangeLog

       PR c/28901
       * cp-objcp-common.c (cxx_warn_unused_global_decl): Remove hard-coded
       VAR_P TREE_READONLY override.

gcc/testsuite/ChangeLog

       PR c/28901
       * g++.dg/warn/unused-variable-1.C: New test.
       * g++.dg/warn/unused-variable-2.C: Likewise.
       * gcc.dg/unused-4.c: Adjust warning for static const.
       * gcc.dg/unused-variable-1.c: New test.
       * gcc.dg/unused-variable-2.c: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227742 138bc75d-0d04-0410-961f-82ee72b054a4
13 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/unused-variable-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/unused-variable-2.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/unused-4.c
gcc/testsuite/gcc.dg/unused-variable-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/unused-variable-2.c [new file with mode: 0644]
gcc/toplev.c