D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21739 - debug case can access variable from other case
Summary: debug case can access variable from other case
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: pull
Depends on:
Blocks:
 
Reported: 2021-03-21 02:24 UTC by moonlightsentinel
Modified: 2021-04-02 20:43 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 moonlightsentinel 2021-03-21 02:24:37 UTC
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.
Comment 1 Dlang Bot 2021-03-21 02:42:55 UTC
@MoonlightSentinel created dlang/dmd pull request #12292 "Fix 21739 - Don't merge `debug case` into previous CaseStatement" fixing this issue:

- Fix 21739 - Don't merge `debug case` into previous CaseStatement
  
  The previous implementation assumed that `CaseStatement`s would be
  seperated by a top-level `case ...`. This is not the case for
  conditionally compiled cases, e.g. `debug { case ...: }`.

https://github.com/dlang/dmd/pull/12292
Comment 2 Dlang Bot 2021-04-02 20:43:40 UTC
dlang/dmd pull request #12292 "Fix 21739 - Don't merge `debug case` into previous CaseStatement" was merged into master:

- dd8a88be3246557f3c82d14f5e5055d6532d9a66 by MoonlightSentinel:
  Fix 21739 - Don't merge `debug case` into previous CaseStatement
  
  The previous implementation assumed that `CaseStatement`s would be
  seperated by a top-level `case ...`. This is not the case for
  conditionally compiled cases, e.g. `debug { case ...: }`.

https://github.com/dlang/dmd/pull/12292