This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/51896] New: Should gcc warn if a variable initializer inside a switch statement is never used?
- From: "kaie at kuix dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 19 Jan 2012 01:35:30 +0000
- Subject: [Bug c/51896] New: Should gcc warn if a variable initializer inside a switch statement is never used?
- Auto-submitted: auto-generated
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â