[Issue 2423] Erroneous unreachable statement warning
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Oct 26 10:27:49 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2423
------- Comment #2 from andrei at metalanguage.com 2008-10-26 12:27 -------
(In reply to comment #1)
> There is also a related issue that will show in the same function if that has a
> return value:
>
> int foo() {
> do {
> return 1;
> } while (true);
> }
>
> warning - whiletrue.d(4): Error: statement is not reachable
> warning - whiletrue.d(1): function whiletrue.foo no return at end of function
>
> I understand that the "no return" is a semantic challenge, but the rule is
> fairly simple: if there is a while(true), then all code after it is dead code
> unless there is also a break. This is also a regression.
>
> Note that whereas the first is an obvious bug and impossible to workaround,
> this one is possible to workaround, but still a question about quality of
> implementation. The "no return" bug does also affect/break Tango when using
> warnings.
In this case there's no doubt a simple flow analysis will take care of things.
The challenge is only when conditions are complex; in this case that doesn't
matter. The code could as well be:
do {
return 1;
} while (P == NP);
My explanation for the bug is that Walter's front-end rewrites loops with
terminal test as loops with initial test with a jump:
do stmt while (cond);
==>
goto __label; while (cond) __label: stmt
The rewritten form makes it a tad more difficult to figure out what's going on.
Andrei
--
More information about the Digitalmars-d-bugs
mailing list