digitalmars.D.bugs - ";" passes as a statement
- Stewart Gordon (27/27) Aug 23 2005 Using DMD 0.128, Windows 98SE.
- Walter (9/9) Aug 26 2005 The compiler does allow empty statements inside { }, as in { ; }, as tho...
- Stewart Gordon (18/27) Aug 28 2005 But that issue would equally be dealt with if we didn't allow ; by
Using DMD 0.128, Windows 98SE. The compiler passes this without error: ---------- void main() { ; } ---------- Nothing in the definition of Statement here http://www.digitalmars.com/d/statement.html permits a semicolon on its own as a statement. As such, it should be at least giving an error of "use '{ }' for an empty statement, not a ';'", just as it does if it's the body of an if, for, foreach, do, while, with or switch. I'd always assumed that disallowing this statement form altogether was how "No empty ; for loop bodies" mentioned in the overview was implemented. It also passes through as the body of a debug, version or static if, or the else clause of any of these. To be honest, I don't get why the compiler is context-sensitive in this respect. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- 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.
Aug 23 2005
The compiler does allow empty statements inside { }, as in { ; }, as those are unlikely to be mistakes. The reason ; by itself isn't allowed in some contexts is because of the: if (foo); { ... } problem. That isn't an issue with { ; }. I agree though the documented grammar should account for this.
Aug 26 2005
In article <denlnh$1mrb$2 digitaldaemon.com>, Walter says...The compiler does allow empty statements inside { }, as in { ; }, as those are unlikely to be mistakes. The reason ; by itself isn't allowed in some contexts is because of the: if (foo); { ... } problem.But that issue would equally be dealt with if we didn't allow ; by itself in _any_ contexts. Actually, it would be even more dealt with, as there would be no risk of you forgetting to add this check to new constructs, as has already happened.That isn't an issue with { ; }.So what? What is the motive for allowing { ; }? AFAICS it serves no purpose but to complicate the parsing algorithm unnecessarily. Moreover, getting rid of it would automatically fix the bug with debug; { .. } and static if(foo); { .. } Stewart.
Aug 28 2005