[Issue 327] New: Compiler accepts ';' by itself as a statement

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 6 12:53:27 PDT 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 at digitalmars.com
        ReportedBy: smjg at 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.


-- 




More information about the Digitalmars-d-bugs mailing list