www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 148] New: Incorrect "statement is not reachable" warning with goto and for loop

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=148

           Summary: Incorrect "statement is not reachable" warning with goto
                    and for loop
           Product: D
           Version: 0.157
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: chris inventivedingo.com


====== testbug.d =======
import std.stdio, std.string;

void main() {
        int i=0;
        writef("This number is zero: ");
        goto inloop;
        for(; i<10; i++) {              // this is line 7
                writef("This number is nonzero: ");
inloop:
                writefln(toString(i));
        }
}
====== ======

D:\D>dmd testbug.d -w
warning - testbug.d(7): statement is not reachable

========
A warning is generated on the line of the for loop, but that statement will of
course will be executed when the loop loops.

Workarounds:
- Compile without warnings
- Change line 6 to: if (1) goto inloop;


-- 
May 20 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=148


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed in DMD 0.160


-- 
Jun 04 2006