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).