www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22995] New: goto case cannot forward to outer case label

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

          Issue ID: 22995
           Summary: goto case cannot forward to outer case label
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

Forward-references to a case inside the same switch works:

void foo(int i, int j)
{
    final switch (i)
    {
        case 1:
            break;
        case 2:
            final switch (j)
            {
                case 4:
                    goto case 3;
                case 3:
                    break;
            }
            break;
    }
}

But fails if the forward-referenced case belongs to an enclosing switch
statement:

void foo(int i, int j)
{
    final switch (i)
    {
        case 1:
            break;
        case 2:
            final switch (j)
            {
                case 4:
                    // goto case 1; // ok
                    goto case 3; // fails
            }
            break;
        case 3:
            break;
    }
}

--
Apr 07 2022