www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17807] New: Spurious dead code warnings with static foreach

https://issues.dlang.org/show_bug.cgi?id=17807

          Issue ID: 17807
           Summary: Spurious dead code warnings with static foreach
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

From: http://forum.dlang.org/post/joevwhpphvzvuijqazbi forum.dlang.org

void trySwitch(int x) {
    import std.stdio : writeln;

    SWITCH: final switch (x) {
        static foreach (y; [ 1, 2, 3 ]) {
            case y:
                writeln("found");
                break SWITCH;
        }
    }
}

void main(string[] args) {
    import std.conv : to;

    trySwitch(args.length > 1 ? to!int(args[1]) : 1);
}


Compilation:

$ dmd -wi ./main.d
./main.d(5): Warning: statement is not reachable
./main.d(5): Warning: statement is not reachable
./main.d(5): Warning: statement is not reachable
./main.d(5): Warning: statement is not reachable

--
Sep 04