Bug 4559 – Disallowing single semicolons

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-08-01T14:24:39Z
Last change time
2018-05-17T16:52:44Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-08-01T14:24:39Z
A low-priority idea. As suggested by Andrei the D language can disallow naked instructions composed by a single semicolon: void main() { int x;; // single semicolons not allowed goto END; END:; // single semicolons not allowed // END: {} // OK } (D already disallows single semicolons at the end of for statements, etc, so this can make the language more uniform.)
Comment #1 by lt.infiltrator — 2017-06-10T06:55:21Z
Does this need a DIP?
Comment #2 by dlang — 2017-06-10T11:53:10Z
I had thought this was an error, but it's just a warning.
Comment #3 by andrei — 2017-06-10T13:06:59Z
No need for a DIP, we should just convert this to an error.
Comment #4 by uplink.coder — 2017-06-10T15:51:09Z
(In reply to Andrei Alexandrescu from comment #3) > No need for a DIP, we should just convert this to an error. If we do this, then we have to special case for(;;). Also it might break an unknown amount of code. At the very least we should have a cost/benefit analysis.
Comment #5 by andrei — 2017-06-10T18:14:12Z
(In reply to uplink.coder from comment #4) > (In reply to Andrei Alexandrescu from comment #3) > > No need for a DIP, we should just convert this to an error. > > If we do this, then we have to special case for(;;). We're in good shape, the semicolons in for are part of the grammar. > Also it might break an unknown amount of code. > At the very least we should have a cost/benefit analysis. The warning has been in there for years. The basic idea is to convert warnings to errors.
Comment #6 by uplink.coder — 2017-06-10T19:02:41Z
(In reply to Andrei Alexandrescu from comment #5) > The warning has been in there for years. The basic idea is to convert > warnings to errors. I just tried : int i;; It compiles just fine without a warning.
Comment #7 by 4burgos — 2017-06-10T19:12:38Z
Not if you compile with `-w`: ``` C:\Users\Burgos>type test.d void main() { int x;; } C:\Users\Burgos>dmd -w test.d test.d(3): Warning: use '{ }' for an empty statement, not a ';' ```
Comment #8 by 4burgos — 2017-06-14T12:06:51Z
Poor dlang bot got confused by my initial typo in the commit message (wrong issue referenced), but the commits are pushed to master: https://github.com/dlang/dmd/pull/6886
Comment #9 by dmitry.olsh — 2018-05-17T16:52:44Z
Today this prints: saa.d(2): Deprecation: use { } for an empty statement, not ; Which is perfectly fine IMHO.