public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/28901]  New: -Wunused-variable ignores unused const initialised variables
@ 2006-08-30 11:55 mikpe at csd dot uu dot se
  2006-09-19  5:13 ` [Bug c/28901] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 13+ messages in thread
From: mikpe at csd dot uu dot se @ 2006-08-30 11:55 UTC (permalink / raw)
  To: gcc-bugs

gcc -Wunused-variable -c test.c, where test.c contains the
following code, fails to warn that variable a is unused:
--begin-test.c-
static const int a = 27;
static const int b = 42;
const int *f(void) { return &b; }
--end-test.c--
However, gcc -Wunused-variable -c -Dconst= test.c does 
produce the warning I wanted:
test.c:1: warning: 'a' defined but not used

The problem is that for some reason, -Wunused-variable ignores
const variables, and there doesn't seem to be any alternative
warning option or variable attribute to request unused warnings
for const variables.

In the application where this was observed, there is a large number
of initialised const arrays-of-structs encoding final-state
information for a state transition engine. Other const variables
and functions encode the fairly complex transition rules. A copy-paste
error in the transition rules led to some final states not being
reachable, i.e., there were no references to those variables, but
-Wunused-variable (implied by -Wall) failed to notice that.


-- 
           Summary: -Wunused-variable ignores unused const initialised
                    variables
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mikpe at csd dot uu dot se


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-09-19  9:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-28901-4@http.gcc.gnu.org/bugzilla/>
2014-01-16 23:52 ` [Bug c/28901] -Wunused-variable ignores unused const initialised variables 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
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

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).