Although I demonstrated this using 4.1.2 on my host, it probably affects
other versions as well.
As the following code shows:
gcc -c -O1 -Wall -Werror uninitialized-warning.c
extern void called_function(unsigned p);
extern unsigned g;
void
f0(unsigned parm)
{
unsigned v;
if (parm == 0) {
v = 4;
}
called_function(v);
}
void
f1(unsigned parm)
{
unsigned v;
if (parm == 0) {
v = 4;
} else {
g = 0;
}
called_function(v);
}
void
f2(unsigned parm)
{
unsigned v;
called_function(v);
}
gcc does not produce the 'uninitialized' warning when the automatic
variable is conditionally assigned.
This gives a very bad false sense of security that the automatic
variables are indeed initialized.
--
Summary: -Wunintialized fails in the face of conditional
assignment.
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thutt at vmware dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37148