This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/78203] missing warning on return of unitialized variable
- From: "fwd at quantentunnel dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 05 Nov 2016 15:03:57 +0000
- Subject: [Bug c/78203] missing warning on return of unitialized variable
- Auto-submitted: auto-generated
- References: <bug-78203-4@http.gcc.gnu.org/bugzilla/>
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.