Bug 8223 – "auto break" switch proposal

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-11T10:52:00Z
Last change time
2016-10-15T13:03:24Z
Assigned to
nobody
Creator
qwertie256

Comments

Comment #0 by qwertie256 — 2012-06-11T10:52:26Z
The switch statement is somewhat tedious due to the need for "break" on every case. It's needed for C compatibility, but it would be nice to be able to request that cases break automatically. Hence, something like: switch(z) auto break { case 0: writeln("empty!"); case 1, 2: writeln("small!"); case 3, 4, 5: writeln("medium!"); default: writeln("large!"); } In case empty cases are adjacent, such as "case 1: case 2:", D should logically make "case 1" a no-op, but warning should be issued because this is the C# syntax for "case 1, 2:". e.g.: warning: "case 1" does nothing. To clarify your intention, use "break" or "case 1, 2".
Comment #1 by andrei — 2016-10-15T13:03:24Z
Thanks. You may want to formulate this as a DIP and see if it gets traction.