Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 08, 2005 bug(?) with "statement is not reachable" warning | ||||
---|---|---|---|---|
| ||||
the file warning.d: int main() { int i = 1; goto skip; do //line #5 { i += 1; skip: t *= 2; i %= 5; } while(0<i && i<5) return i; } when compiled with v0.127 using: dmd warning.d -w returns warning - warning.d(5): statement is not reachable |
July 08, 2005 Re: bug(?) with "statement is not reachable" warning | ||||
---|---|---|---|---|
| ||||
Posted in reply to shro8822 | It's a fine example of why I don't like warnings about "unreachable" code. I can trick about every compiler into generating spurious warnings or missing important cases. Whether a statement is reachable or not can only be computed properly with data flow analysis, which is done by the optimizer long after the semantic passes are complete. The semantic pass uses a primitive, brain-damaged form of data flow analysis. My recommendation is to not worry about it. P.S. Many programmers consider jumping forward into the middle of a loop as bad form. May I suggest instead of: int i = 1; goto skip; do //line #5 { i += 1; skip: t *= 2; i %= 5; } while(0<i && i<5) return i; write: int i = 1; while (1) { t *= 2; i %= 5; if (i <= 0 || i >= 5) break; i++; } return i; |
July 09, 2005 Re: bug(?) with | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | >int i = 1;
>goto skip;
>do //line #5
>{
>i += 1;
>skip:
>t *= 2;
>i %= 5;
>}
>while(0<i && i<5)
>return i;
>
Actually that was is a contrived example. What I found gets rid of the error is to label the loopwith a dummy label. A fix to the erroneous warning might be to look for labels in a loop and treat that as the whole loop being reachable.
int i = 1;
goto skip;
kluge: do //line #5
{
i += 1;
skip:
t *= 2;
i %= 5;
}
while(0<i && i<5)
return i;
|
Copyright © 1999-2021 by the D Language Foundation