http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46853
Summary: gcc fails to warn about uninitialized variable Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: gcc-b...@nospam.pz.podzone.net With the code below gcc warns of uninitialised variable only when not nested in a loop. The test case is simple enough. I think gcc should be able to check for this. The 'FOR_LOOP' test case has also been checked with GNU C (GCC) version 4.4.3 (arm-unknown-elf), and gcc (Debian 4.4.5-8) 4.4.5, with the same behaviour as below. $ cat gcc_test.c int func(void); int main(void) { int foo; foo = func(); return foo; } int func(void) { int foo; #if defined (FOR_LOOP) int i; for (i = 0; i < 5; i++) #elif defined (WHILE_LOOP) while(1) #endif { if (foo == 0x00) /* uninitialised use */ { foo = 0xFF; } } return foo; } $ gcc gcc_test.c -Os -Wall -Wextra -Wuninitialized gcc_test.c: In function `func': gcc_test.c:29: warning: `foo' is used uninitialized in this function $ gcc gcc_test.c -Os -Wall -Wextra -Wuninitialized -DFOR_LOOP $ gcc gcc_test.c -Os -Wall -Wextra -Wuninitialized -DWHILE_LOOP $ gcc --version gcc (GCC) 4.3.4 20090804 (release) 1 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $