D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4559 - Disallowing single semicolons
Summary: Disallowing single semicolons
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-01 14:24 UTC by bearophile_hugs
Modified: 2018-05-17 16:52 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-08-01 14:24:39 UTC
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 Infiltrator 2017-06-10 06:55:21 UTC
Does this need a DIP?
Comment 2 dlang 2017-06-10 11:53:10 UTC
I had thought this was an error, but it's just a warning.
Comment 3 Andrei Alexandrescu 2017-06-10 13:06:59 UTC
No need for a DIP, we should just convert this to an error.
Comment 4 uplink.coder 2017-06-10 15:51:09 UTC
(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 Andrei Alexandrescu 2017-06-10 18:14:12 UTC
(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 Stefan Koch 2017-06-10 19:02:41 UTC
(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 Nemanja Boric 2017-06-10 19:12:38 UTC
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 Nemanja Boric 2017-06-14 12:06:51 UTC
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 Dmitry Olshansky 2018-05-17 16:52:44 UTC
Today this prints:

saa.d(2): Deprecation: use { } for an empty statement, not ;

Which is perfectly fine IMHO.