On Thu, 4 Sep 2025, Martin Uecker wrote:
> This change adds a warning -Wuse-after-missed-init which is similar to
> -Wjump-misses-init but better supports idiomatic C code by emitting a
> diagnostic only when the variable is used somewhere after the label,
> e.g. no warning is emitted in the following example. The new warning
> is activated for -Wall.
I'm not sure how reliable this approach can be, as something reliable
might need to be flow-sensitive. The tests don't really seem to cover the
interesting cases (which I'd hope would be covered even if not
implemented), such as:
goto label;
int i = 1;
while (true)
{
return i;
label:
}
where i is used with the initialization having been skipped, but lexically
the label appears after the use of i, or
goto label;
int i = 1;
if (true)
{
label: return 0;
}
else
return i;
where the label appears lexically before the use of i but the use isn't
reachable from the label.
> + else if (!lookup_name_in_scope (DECL_NAME (decl), current_scope))
> + {
> + /* The are already after the scope where the variable is declared,
"The are" seems wrong.
Also, lookup_name_in_scope seems suspect here. What if the name is
declared in the current scope but it's a different, unrelated declaration
- can that happen with this code?
--
Joseph S. Myers
[email protected]