digitalmars.D.bugs - bug(?) with "statement is not reachable" warning
- shro8822 uidaho.edu (19/19) Jul 08 2005 the file warning.d:
- Walter (32/32) Jul 08 2005 It's a fine example of why I don't like warnings about "unreachable" cod...
- B Shropshire (14/25) Jul 09 2005 Actually that was is a contrived example. What I found gets rid of the e...
the file warning.d: int main() { int i = 1; goto skip; { 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
Jul 08 2005
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; { 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;
Jul 08 2005
int i = 1; goto skip; { 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; { i += 1; skip: t *= 2; i %= 5; } while(0<i && i<5) return i;
Jul 09 2005