public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mikpe at csd dot uu dot se" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/28901] New: -Wunused-variable ignores unused const initialised variables Date: Wed, 30 Aug 2006 11:55:00 -0000 [thread overview] Message-ID: <bug-28901-7665@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2006-08-30 11:55 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-08-30 11:55 mikpe at csd dot uu dot se [this message] 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-7665@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: linkBe 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).