Thread overview
[Issue 327] New: Compiler accepts ';' by itself as a statement
Sep 06, 2006
d-bugmail
Nov 15, 2006
d-bugmail
Nov 15, 2006
d-bugmail
Nov 18, 2006
d-bugmail
Nov 19, 2006
d-bugmail
Nov 19, 2006
d-bugmail
Nov 19, 2006
d-bugmail
Nov 19, 2006
Stewart Gordon
Jul 26, 2009
Stewart Gordon
September 06, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327

           Summary: Compiler accepts ';' by itself as a statement
           Product: D
           Version: 0.165
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: smjg@iname.com


The following code compiles without error:

----------
void main() {
    ;
}
----------

and produces a program that does nothing.

Nothing in the D spec allows a semicolon on its own to be used as a statement. Nonetheless, the current compiler allows it.  It has, however, made exceptions for certain control structures, e.g. it rejects

    if (...) ;
    for (...) ;

while allowing some other similar forms.

The language would gain nothing by allowing ';' as a statement in any context. In C, it may have had its uses in conjunction with preprocessor macros.  But in D, which has no macro preprocessor, no such use cases exist.

Moreover, it is much simpler to disallow such a useless statement form altogether than to let it through and then catch a handful of specific cases.

There was once a specific exception, to the effect of

LabelledStatement:
    Identifier ':' Statement
    Identifier ':' ';'

but this has since disappeared from the spec.  But if for any reason this is ever reinstated, then implementing it explicitly would still be a lot simpler than the mess things are in at the moment.

Existing DStress testcases: http://dstress.kuehne.cn/nocompile/e/ExpressionStatement_06_A.d et seq.


-- 

November 15, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327


lio@lunesu.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor




------- Comment #1 from lio@lunesu.com  2006-11-15 02:16 -------
Fixing this would break goto labels at the end of a function. These labels should now be followed by a single colon, since they label a statement, even an empty one. I'm setting severity to minor.


-- 

November 15, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327





------- Comment #2 from smjg@iname.com  2006-11-15 06:31 -------
Please clarify.  Why do you feel that the explicit solution I've clearly given for the LabelledStatement issue won't work?


-- 

November 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla@digitalmars.com  2006-11-18 16:47 -------
Updated the spec to allow this.


-- 

November 19, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Comment #4 from smjg@iname.com  2006-11-19 08:01 -------
Why won't you tell us why?

And even if one were to accept this change, I don't consider it fixed at all, because the compiler is still accepting it even in some cases where the design of D is to forbid it.  See DStress testcases ExpressionStatement_07_* and ExpressionStatement_08_*.


-- 

November 19, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327





------- Comment #5 from smjg@iname.com  2006-11-19 08:38 -------
(In reply to comment #4)
> Why won't you tell us why?

I should've replied to your mention on the newsgroup of case and default statements before I wrote that.  Well, I have now.


-- 

November 19, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=327


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID




------- Comment #6 from bugzilla@digitalmars.com  2006-11-19 14:32 -------
Both DebugStatement and VersionStatement allow a ';' as a statement, as both have Statement in the grammar, and Statement includes ';'. In other words, this is not a bug as the spec matches the implementation. If you want to change it, it should be marked as an enhancement request, not a bug.

As to why allow empty statements, 1) such are common in C like languages and are expected to be there and 2) they are 'boundary' or 'degenerate' cases and can be handy to have as markers, placeholders, or to just make it easier for programs that generate source code as output. They don't hurt anything.


-- 

November 19, 2006
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=327
> 
> 
> bugzilla@digitalmars.com changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|REOPENED                    |RESOLVED
>          Resolution|                            |INVALID
> 
> ------- Comment #6 from bugzilla@digitalmars.com  2006-11-19 14:32 -------
> Both DebugStatement and VersionStatement allow a ';' as a statement, as both
> have Statement in the grammar, and Statement includes ';'. In other words, this
> is not a bug as the spec matches the implementation. If you want to change it,
> it should be marked as an enhancement request, not a bug.

Regardless of the obviousness that leaving it specified this way was a slip-up?

> As to why allow empty statements, 1) such are common in C like languages and
> are expected to be there

Expected by whom?

> and 2) they are 'boundary' or 'degenerate' cases and
> can be handy to have as markers, placeholders, or to just make it easier for
> programs that generate source code as output. They don't hurt anything.

Hmm....

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
July 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=327


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED




--- Comment #7 from Stewart Gordon <smjg@iname.com>  2009-07-26 16:01:26 PDT ---
The INVALID resolution was due to a mistake in the spec that has since been fixed.  And the original issue was fixed by changing the spec.  Reverting resolution.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------