www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 327] New: Compiler accepts ';' by itself as a statement

reply d-bugmail puremagic.com writes:
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.


-- 
Sep 06 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327


lio lunesu.com changed:

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





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.


-- 
Nov 15 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327






Please clarify.  Why do you feel that the explicit solution I've clearly given
for the LabelledStatement issue won't work?


-- 
Nov 15 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327


bugzilla digitalmars.com changed:

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





Updated the spec to allow this.


-- 
Nov 18 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327


smjg iname.com changed:

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





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_*.


-- 
Nov 19 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327







 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. --
Nov 19 2006
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327


bugzilla digitalmars.com changed:

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





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.


-- 
Nov 19 2006
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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
 

 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.
Nov 19 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=327


Stewart Gordon <smjg iname.com> changed:

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





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: -------
Jul 26 2009