public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/51896] New: Should gcc warn if a variable initializer inside a switch statement is never used?
@ 2012-01-19 2:23 kaie at kuix dot de
2012-01-19 10:12 ` [Bug c/51896] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: kaie at kuix dot de @ 2012-01-19 2:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51896
Bug #: 51896
Summary: Should gcc warn if a variable initializer inside a
switch statement is never used?
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kaie@kuix.de
While maintaining existing code, we encountered a snippet like this:
--------------- begin test.c -----------------------
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char *argv[])
{
int *a = (int*)0xaaaaaaaa;
printf("a is: %p\n", a);
int r = rand() % 2;
switch (r)
{
int *b = (int*)0xbbbbbbbb;
case 2: break;
default:
printf("b is: %p\n", b);
}
return 0;
}
--------------- end test.c -----------------------
$ gcc -o test -Wall test.c
test.c: In function ‘main’:
test.c:17:13: warning: ‘b’ may be used uninitialized in this function
[-Wuninitialized]
$ ./test
a is: 0xaaaaaaaa
b is: 0x434b5fc4
Proposal:
As gcc decides to ignore value 0xbbbbbbbb, it should print a warning message,
informing the user, e.g.:
test.c: warning: ignoring initialization value ‘0xbbbbbbbb’
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/51896] Should gcc warn if a variable initializer inside a switch statement is never used?
2012-01-19 2:23 [Bug c/51896] New: Should gcc warn if a variable initializer inside a switch statement is never used? kaie at kuix dot de
@ 2012-01-19 10:12 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-01-19 10:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51896
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-01-19
Ever Confirmed|0 |1
Severity|normal |enhancement
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-19 10:04:01 UTC ---
Confirmed. This is similar to
int
main(int argc, char *argv[])
{
goto _default;
{
int *b = (int*)0xbbbbbbbb;
_default:
printf("b is: %p\n", b);
}
return 0;
}
thus, when you jump across an init expression and still use the variable.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-19 10:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-19 2:23 [Bug c/51896] New: Should gcc warn if a variable initializer inside a switch statement is never used? kaie at kuix dot de
2012-01-19 10:12 ` [Bug c/51896] " rguenth at gcc dot gnu.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).