Bug 7133 – [tdpl] There should be no empty statement
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-12-18T18:17:00Z
Last change time
2011-12-29T02:23:17Z
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2011-12-18T18:17:17Z
The statement ";" should not exist. It is never needed, never useful, and in most cases the compiler requires it to be replaced with '{}'.
Walter and I agreed on all of the above so ";" is not present in TDPL. It should be slowly deprecated and ultimately removed from D. It is just junk in the trunk.
Comment #1 by issues.dlang — 2011-12-18T18:25:35Z
The one case that I'm aware of where some have argued for its value is labels. e.g.
LABEL:;
Since labels require a statement, ; makes it so that you can you can use a label without really having a statement. I'm not sure that that merits keeping it however, since in every other use case that I can think of, it has no value.
Comment #2 by andrei — 2011-12-18T18:26:14Z
LABEL: {}
is as good and marginally nicer.
Comment #3 by issues.dlang — 2011-12-18T18:28:18Z
I didn't think that that worked, since {} isn't a statement (at least, as far as I know, it isn't), but if it works, it's certainly better.
Comment #4 by andrei — 2011-12-18T20:06:48Z
{} is the empty statement in D.
Comment #5 by issues.dlang — 2011-12-18T20:11:40Z
Is that different from C++? I thought that {} was just an empty scope without any statements in it at all in both C/C++ and D.
Comment #6 by smjg — 2011-12-19T05:07:21Z
(In reply to comment #5)
> Is that different from C++? I thought that {} was just an empty scope without
> any statements in it at all in both C/C++ and D.
It is, but in 100% of cases the compiler can optimise away that empty scope and so it's equivalent to an empty statement.
Comment #7 by jakobovrum — 2011-12-19T05:16:39Z
(In reply to comment #3)
> I didn't think that that worked, since {} isn't a statement (at least, as far
> as I know, it isn't), but if it works, it's certainly better.
It is indeed a statement, it's called a block statement, also in D:
http://dlang.org/statement.html#BlockStatement
Comment #8 by timon.gehr — 2011-12-19T06:23:35Z
(In reply to comment #0)
> The statement ";" should not exist. It is never needed, never useful, and in
> most cases the compiler requires it to be replaced with '{}'.
>
> Walter and I agreed on all of the above so ";" is not present in TDPL. It
> should be slowly deprecated and ultimately removed from D. It is just junk in
> the trunk.
I think it is useful. This looks odd:
int i = 2;
for({} i<2; i++){}
Comment #9 by smjg — 2011-12-19T07:17:31Z
(In reply to comment #8)
> I think it is useful. This looks odd:
>
> int i = 2;
> for({} i<2; i++){}
The ; you're replacing there isn't a statement - it's something explicitly allowed by the ForStatement syntax.
ForStatement:
for (Initialize Testopt ; Incrementopt) ScopeStatement
Initialize:
;
NoScopeNonEmptyStatement
Comment #10 by clugdbug — 2011-12-24T04:41:20Z
(In reply to comment #2)
> LABEL: {}
>
> is as good and marginally nicer.
Bear in mind that it only ever happens at the end of a block, so the next character is always a }.
The existing label syntax needs to be retained for asm statements, though, since they don't have {}.
asm {
jmp done;
done:
;
}
which is already ugly, and will look really silly when nude ; statements are gone. I wish we could get rid of that silly semicolon.
In fact the oddity is that labels are considered to be statements, yet they don't end with a semicolon.
Comment #11 by jakobovrum — 2011-12-25T01:03:29Z
(In reply to comment #10)
> In fact the oddity is that labels are considered to be statements, yet they
> don't end with a semicolon.
Block, if, while, do, for, foreach, switch, with, etc. Most types of statements don't end with a semicolon.
Remember that the label statement is:
Identifier : NoScopeStatement
The following statement is a sub-statement of the label statement. It's not any more inconsistent than other statements with sub-statements.