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.