Bug 10199 – labels cannot be used without a statement

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-29T03:05:00Z
Last change time
2015-06-17T21:03:44Z
Keywords
pull
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-05-29T03:05:54Z
Basically, if I have a "end:" label, that is followed by nothing (because, well, end; the function is over), it is considered wrong: //----- void main() { goto end; end: //main.d(5): Error: found '}' instead of statement } //----- Workaround is to use a dummy statement: //----- void main() { goto end; end: ; //OK: Found a statement } //----- I'd also note that the workaround should be considered a bug, just the same way you aren't allowed to use an empty statement after a if/else/for/while. I think the workaround should be turned down, in favor of: //----- void main() { goto end; end: {} //OK: Found an (explicitly empty) statement } //----- But this point is minor, the problem is that a label *can't* be used without an identifier.
Comment #1 by alex — 2013-05-29T03:09:07Z
This is by design. Labels in D aren't just "labels", they are labelled statements; not the same thing as in C. You're supposed to use `{}` to denote an empty statement to jump to. `;` being allowed is a legacy artifact that will (hopefully!) be killed eventually.
Comment #2 by yebblies — 2013-12-24T22:01:22Z
I want this.
Comment #3 by yebblies — 2013-12-24T22:08:42Z
Comment #4 by github-bugzilla — 2013-12-30T11:42:36Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/34c35531845cf1bbe00fa6517d8372330f83ccb6 Fix Issue 10199 - labels cannot be used without a statement https://github.com/D-Programming-Language/dmd/commit/ea43dca7555f0e3047f30e398d33c5f211018ca4 Merge pull request #3022 from yebblies/issue10199 Issue 10199 - labels cannot be used without a statement
Comment #5 by github-bugzilla — 2015-03-29T07:39:15Z
Comment #6 by github-bugzilla — 2015-06-17T21:03:44Z