[Bug c/87038] diagnostics: Please add warning for jumping over initializers with switch/case in C mode

harald at gigawatt dot nl gcc-bugzilla@gcc.gnu.org
Sun Oct 21 18:59:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87038

--- Comment #15 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Segher Boessenkool from comment #10)
> The initialisation (the call to f1) could have a side effect, but the
> a==1 case skips that.  GCC is right to warn here in my opinion.

With an explicit -Wjump-misses-init, sure, that's the point of the warning.
With -Wall, no, as there is nothing wrong with the code and it's quite
intentional that the initialisation is skipped. Would you recommend to the
author of whoever wrote that that the initialiser should be taken out of the
declaration and put in an assignment on a separate line? That makes no sense to
me. (And by the way, this is not hypothetical. This warning *does* trigger on
code I work on.)

The side effect is irrelevant, by the way, as the warning is triggered even if
the initialiser is constant. And warnings that are likely to trigger on
perfectly valid code that behaves exactly as the author intended shouldn't be
included in -Wall, per your own comment.


More information about the Gcc-bugs mailing list