http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46684
Summary: GCC throws incorrect "may be used uninitialized"
warnings
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
Originally reported: https://bugzilla.novell.com/238855
% 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