[Bug c/49754] Let gcc warn about all uninitialized variables

giecrilj at stegny dot 2a.pl gcc-bugzilla@gcc.gnu.org
Fri Jul 15 11:01:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49754

--- Comment #5 from Christopher Yeleighton <giecrilj at stegny dot 2a.pl> 2011-07-15 11:00:28 UTC ---
(In reply to comment #3)
> (In reply to comment #2)
> > Since (x) is uninitialized, so is (x.i).
> 
> But what if x.i gets initialized, is x still uninitialized?

If (x.i) denotes an object type and the initial value means "x is empty" then x
is initialized.

> 
> struct X { int i; };
> struct Y { int i; int j; };
> 
> int main()
> {
>   X x;
>   x.i = 0;   // is 'x' initialized now?
>   Y y;
>   y.i = 0;   // is 'y' initialized now?
>   y.j = 0;   // is 'y' initialized now?
> }
> 
> 
> It would be possible to track the initialization of each subobject *and* the
> aggregate, but it would be more overhead

I have already bumped into this using arrays, where GCC does emit a warning
although it should not:

int a [02]; 
for (a [0] = 0;;) if (a [0]) printf ("%d", +a [1]); else a [0] = a [1] = 01;



More information about the Gcc-bugs mailing list