[Bug c/78203] missing warning on return of unitialized variable
fwd at quantentunnel dot de
gcc-bugzilla@gcc.gnu.org
Sat Nov 5 15:04:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78203
--- Comment #2 from fwd <fwd at quantentunnel dot de> ---
(In reply to Richard Biener from comment #1)
> There is a duplicate for this, we perform optimistic constant propagation
> which
> makes i == 1 and eliminates the conditional uninitialized use very early.
Well, with optimization -O2 the "optimistic constant propagation" is performed
and the return value is constant.
Nevertheless, I think the warning should be given, at least with '-Wpedantic'.
I wouldn't expect a constant there. If I had tests for this code, the tests
might become dependent on the optimization level.
If the constant value is exchanged by a variable of global scope, the warning
is given.
int e = 0;
int func1(const int x)
{
int i;
if (0 == x)
{
i = e;
}
return i;
}
In my opinion, the warning should be given because of "ambiguous" code, even
though "optimistic constant propagation" removes one branch of the conditional.
More information about the Gcc-bugs
mailing list