Bug 3005 – ill-defined for statement

Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P5
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-05-17T15:02:00Z
Last change time
2015-06-09T05:15:16Z
Keywords
spec
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2009-05-17T15:02:25Z
This compiles and runs: void main() { int x = 2; for (while (false) x = 2; x != 2; ) {} } along with some other similarly odd constructs.
Comment #1 by shro8822 — 2009-05-17T15:14:35Z
That's been known for some time. It's done that way to allow this to work: for(int a = 5; a < 10; a++) {} ----[statment] I think the best "fix" would be to switch from a statement, to allowing an expression or declaration. OTOH I'm fine with it as it is as it doesn't cause any known problems with "reasonable" code.
Comment #2 by smjg — 2009-05-19T10:44:13Z
(In reply to comment #1) > That's been known for some time. It's done that way to allow this to work: > > for(int a = 5; a < 10; a++) {} > ----[statment] > > I think the best "fix" would be to switch from a statement, to allowing an > expression or declaration. That's how I thought it was defined - but it turns out ForStatement: for ( Initialize Test ; Increment ) ScopeStatement Initialize: ; NoScopeNonEmptyStatement so I was wrong about this being accepts-invalid.
Comment #3 by bugzilla — 2012-01-19T12:20:43Z
I'll mark it as invalid, then.
Comment #4 by andrei — 2012-01-19T12:39:17Z
Cool, this is going to make for some interesting plays :o).