Issue 17807 - Spurious dead code warnings on enum and static variables.
Summary: Spurious dead code warnings on enum and static variables.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2017-09-04 19:54 UTC by timon.gehr
Modified: 2017-10-01 20:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2017-09-04 19:54:33 UTC
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
Comment 1 timon.gehr 2017-09-04 20:36:07 UTC
Reduced test case:

int main(string[] args){
    int y=0;
    import std.conv;
    switch(args[1].to!int){
        { case 0: break; }
        enum x=0;
        default: y=x;
    }
    return y;
}
Comment 2 timon.gehr 2017-09-04 21:20:28 UTC
https://github.com/dlang/dmd/pull/7120
Comment 3 github-bugzilla 2017-09-15 04:59:30 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/e606297c9138747dc71732046547b5a19829fb05
fix Issue 17807 - Spurious dead code warnings on enum and static variables.

https://github.com/dlang/dmd/commit/891b53a68f253c22b8b857ca66009d0a1df4c963
Merge pull request #7120 from tgehr/fix17807

fix Issue 17807 - Spurious dead code warnings on enum and static variables.
Comment 4 github-bugzilla 2017-10-01 20:41:00 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/e606297c9138747dc71732046547b5a19829fb05
fix Issue 17807 - Spurious dead code warnings on enum and static variables.

https://github.com/dlang/dmd/commit/891b53a68f253c22b8b857ca66009d0a1df4c963
Merge pull request #7120 from tgehr/fix17807