public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mark at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/28901] -Wunused-variable ignores unused const initialised variables
Date: Mon, 14 Sep 2015 09:50:00 -0000	[thread overview]
Message-ID: <bug-28901-4-T1Yt1weRjQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-28901-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28901

--- Comment #9 from Mark Wielaard <mark at gcc dot gnu.org> ---
Author: mark
Date: Mon Sep 14 09:49:47 2015
New Revision: 227742

URL: https://gcc.gnu.org/viewcvs?rev=227742&root=gcc&view=rev
Log:
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.

Added:
    trunk/gcc/testsuite/g++.dg/warn/unused-variable-1.C
    trunk/gcc/testsuite/g++.dg/warn/unused-variable-2.C
    trunk/gcc/testsuite/gcc.dg/unused-variable-1.c
    trunk/gcc/testsuite/gcc.dg/unused-variable-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c.opt
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-objcp-common.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/unused-4.c
    trunk/gcc/toplev.c


  parent reply	other threads:[~2015-09-14  9:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-28901-4@http.gcc.gnu.org/bugzilla/>
2014-01-16 23:52 ` pinskia at gcc dot gnu.org
2014-01-16 23:55 ` pinskia at gcc dot gnu.org
2014-01-17  0:26 ` hjl.tools at gmail dot com
2014-02-11 17:39 ` tromey at gcc dot gnu.org
2014-08-08 14:18 ` tromey at gcc dot gnu.org
2014-10-22 18:55 ` petschy at gmail dot com
2015-09-11 22:15 ` mark at gcc dot gnu.org
2015-09-14  9:50 ` mark at gcc dot gnu.org [this message]
2015-09-18 23:06 ` eggert at gnu dot org
2015-09-18 23:43 ` manu at gcc dot gnu.org
2015-09-19  4:51 ` eggert at gnu dot org
2015-09-19  9:27 ` manu at gcc dot gnu.org
2006-08-30 11:55 [Bug c/28901] New: " mikpe at csd dot uu dot se
2006-09-19  5:13 ` [Bug c/28901] " pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-28901-4-T1Yt1weRjQ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).