Bug 15535 – Emit error on "goto default" in final switch

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-09T21:31:00Z
Last change time
2016-03-19T20:21:39Z
Assigned to
nobody
Creator
jbc.engelen

Comments

Comment #0 by jbc.engelen — 2016-01-09T21:31:34Z
This code compiles, but I think it shouldn't: void main() { int i; final switch(i) { case 1: goto default; } } When executed, the program immediately crashes. Because a final switch cannot have a "default:" case, I think the compiler error on this code.
Comment #1 by jbc.engelen — 2016-01-09T21:43:36Z
(This is probably mostly a note to self.) Note that "goto default" means to go to the default label of the current switch statement only. So this does not work: void main() { int i = 1; switch (i) { case 1: final switch(i) { case 1: goto default; } default: i = 666; break; } assert(i == 666); } The code compiles and when run will throw core.exception.SwitchError@gotodefault(6): No appropriate switch clause found (line 6 contains the "goto default")
Comment #2 by github-bugzilla — 2016-01-15T17:24:57Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3e245ec352f97705e7fe383f9b6a350c14d29148 fix Issue 15535 - Disallow "goto default" in final switches. https://github.com/D-Programming-Language/dmd/commit/8968b7bf8a3be265d348e3d5477ec5485938ad02 Merge pull request #5343 from JohanEngelen/fail15535 fix Issue 15535 - Disallow "goto default" in final switches.
Comment #3 by github-bugzilla — 2016-03-19T20:21:39Z