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: unassig...@gcc.gnu.org ReportedBy: k...@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’