www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10532] New: Silence some unreachable statement warnings when in a static foreach

http://d.puremagic.com/issues/show_bug.cgi?id=10532

           Summary: Silence some unreachable statement warnings when in a
                    static foreach
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-07-03
18:34:26 PDT ---
-----
import std.traits;

enum E { a, b}

void main()
{
    foreach (e; EnumMembers!E)
    {
        if (e == E.a)
            continue;

        // lots of code follows..

        auto x = 1;
    }
}
-----

$ dmd -w test.d
 test.d(14): Warning: statement is not reachable
I don't know if this is doable, but it's a little annoying that we have these unreachable statement warnings when in a static foreach loop. It forces use to use an else statement, but this introduces indentation. In this specific test-case the alternative could be to Filter!() through the EnumMembers so "E.a" never appears in the loop, but for more complex cases such filtering may not be usable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 03 2013