www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21739] New: debug case can access variable from other case

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

          Issue ID: 21739
           Summary: debug case can access variable from other case
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

Consider the following code:

void main()
{
    int i;
    switch (i)
    {
        case 0:
            int x;
            break;

        case 1:
            x = 1;
            break;

        case 2:
            int y;
            break;

        debug
        {
            case 3:
                y = 1; // Accepted
                break;
        }

        default:
    }
}

DMD rightfully complains that `case 1:` cannot see x but accepts `case 3:`
accessing y.

--
Mar 20 2021