https://bugzilla.novell.com/show_bug.cgi?id=238855 Summary: GCC throws strange 'is used uninitialized' warnings Product: openSUSE 10.2 Version: Final Platform: Other OS/Version: Other Status: NEW Severity: Normal Priority: P5 - None Component: Development AssignedTo: matz@novell.com ReportedBy: matz@novell.com QAContact: qa@suse.de CC: max@novell.com, rguenther@novell.com Reinhard Max just showed me funny circumstance under which this warning is thrown or not thrown. % cat x.c enum BLA {A, C}; int f (enum BLA a, int i) { int ret, ret2; switch (a) { case A: ret2=42; if (i) ret=1; else ret=3; break; case C: ret = 2; ret2=1; break; } if (ret2 || ret) return 42; return 43; } % gcc -W -Wall -O2 -c x.c x.c: In function ‘f’: x.c:16: warning: ‘ret2’ is used uninitialized in this function x.c:16: warning: ‘ret’ is used uninitialized in this function It's not "is" but should be "may be", as at least one path initializes all variables. Stranger even is if you change the source a bit: % cat x2.c enum BLA {A, C}; int f (enum BLA a, int i) { int ret, ret2; switch (a) { case A: //ret2=42; if (i) ret=1; else ret=3; break; case C: ret = 2; ret2=1; break; } if (ret2 || ret) return 42; return 43; } (note the missing initialization of ret2 in the A arm). Now it doesn't warn at all: % gcc -c -W -Wall -O2 x2.c % Now, we can change it a bit more, and get "may be" warnings: % cat x3.c enum BLA {A, B, C}; int f (enum BLA a, int i) { int ret, ret2; switch (a) { case A: case B: //if (i) ret=1; else ret=3; ret = 1; ret2=42; break; case C: ret = 2; ret2=1; break; } if (i || ret || ret2) return 42; return 43; } Note the missing 'if' and the changed second if condition. It's now: % gcc -c -W -Wall -O2 x3.c x.c: In function ‘f’: x.c:5: warning: ‘ret2’ may be used uninitialized in this function x.c:5: warning: ‘ret’ may be used uninitialized in this function Something is rotten. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.