[Issue 13858] Wrong warning about unreachable code with break/goto case
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Jan 24 01:52:42 PST 2015
https://issues.dlang.org/show_bug.cgi?id=13858
yebblies <yebblies at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yebblies at gmail.com
--- Comment #3 from yebblies <yebblies at gmail.com> ---
(In reply to Andrej Mitrovic from comment #1)
> Also, the same thing happens with 'goto', although I'm not sure whether
> there's a semantic difference between the two (I assume so).
If by that you mean replacing the 'break LSwitch' with 'goto LSwitch' then the
warning is correct, because that would be an infinite loop.
The problem here is that LabelStatement::blockExit just returns the blockExit
of the labeled statement, and isn't really designed for handling a label
containing a goto to itself.
BreakStatement::blockExit produces BEgoto when used with a label, but this is
overly vague, as labeled breaking from a switch should produce BEfallthru.
I tried changing SwitchStatement::blockExit to treat an internal BEgoto as
BEfallthrough, like ForStatement does, but it seems to also use BEgoto to
indicate internal 'goto case's and that change leads to false positive "no
return exp; or assert(0)" errors.
I'm not sure it's possible to fix this without properly building and walking a
CFG, maybe somebody else knows for sure.
--
More information about the Digitalmars-d-bugs
mailing list