Bug 12640 – Error inside a switch statement causes a spurious switch case fallthrough warning

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-25T01:59:00Z
Last change time
2014-04-25T11:29:24Z
Keywords
diagnostic, pull
Assigned to
andrej.mitrovich
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-04-25T01:59:50Z
void main() @nogc { int[1] bar; int x; switch (x) { case 0: bar = [x]; break; default: } } DMD 2.066alpha gives this, the warning is false (a rejects-valid, you can see it removing the @nogc annotation): test.d(6,19): Error: array literals in @nogc function main may cause GC allocation test.d(8,9): Warning: switch case fallthrough - use 'goto default;' if intended
Comment #1 by andrej.mitrovich — 2014-04-25T08:02:13Z
This isn't really specific to @nogc, there are other cases where an error inside of a switch causes a fallthrough diagnostic.
Comment #2 by andrej.mitrovich — 2014-04-25T08:03:23Z
Changed title. Reduced test-case: ----- void main() { switch (1) { case 0: asdf; break; default: } } -----
Comment #3 by andrej.mitrovich — 2014-04-25T08:18:04Z
Comment #4 by github-bugzilla — 2014-04-25T11:29:23Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/567f589ebd6a49c2420c38a44e5469d47956f46c Fix Issue 12640 - Avoid fallthrough diagnostics when the last case/default statement in a switch failed semantic analysis. https://github.com/D-Programming-Language/dmd/commit/c5ebee1dc7c41f53eaa9b86c44c6059fbd58ebad Merge pull request #3496 from AndrejMitrovic/Fix12640 Issue 12640 - Avoid fallthrough diagnostics when the last case/default statement failed.