[Issue 4349] New: Deprecate automatic case fallthrough

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 19 13:06:51 PDT 2010


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

           Summary: Deprecate automatic case fallthrough
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-06-19 13:06:48 PDT ---
Bugs caused by unwanted fall-through between cases in switch statement are
common enough to push designers of other languages (like C#) to find ways to
avoid them.

D2 has already in place all is necessary to avoid this source of problems. The
only missing part is to disallow cases that miss an explicit return, goto,
break, assert(0), exit(), or similar.

C code ported to D that assumes the fall-through will just raise errors that
can be solved adding "goto case;" at the end of the cases.

The usage of "goto case;" will not be excessive because D allows both ranged
cases and multiple with a comma that allow to compress switch code.

case 1, 2, 3:
case 1: .. case 3:

As for the multiple returns in a function this kind of code needs some care:

switch (x) {
    case 0:
        if (y)
            goto case;
        else
            return x;
    default:
        break;
}


Bug 3536 shows an alternative proposal.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list