[Issue 1605] New: break in switch with goto breaks in ctfe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 21 08:34:13 PDT 2007


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

           Summary: break in switch with goto breaks in ctfe
           Product: D
           Version: 1.022
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: lutger.blijdestijn at gmail.com


I stumbled upon a case where a break statement in a switch causes the outer
while loop to exit. This happens only when the function is evaluated at compile
time and a goto statement is involved. Forgive me the bad example: 

int Break()
{
    int i = 0;
    while (true)
    {
        switch(i)
        {
            case 0:
            goto LABEL; // comment out this line and all is fine
             LABEL:
                // at compile time, this breaks out of the while loop:
                break;
            default:
                return i;
        }
        i = 1;
    }
    return 0; // unreachable
}

void main()
{
    assert (Break() == 1); // ok
    static assert(Break() == 1); // not ok
}


-- 



More information about the Digitalmars-d-bugs mailing list