D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3005 - ill-defined for statement
Summary: ill-defined for statement
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P5 minor
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2009-05-17 15:02 UTC by Andrei Alexandrescu
Modified: 2015-06-09 05:15 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-05-17 15:02:25 UTC
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 BCS 2009-05-17 15:14:35 UTC
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 Stewart Gordon 2009-05-19 10:44:13 UTC
(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 Walter Bright 2012-01-19 12:20:43 UTC
I'll mark it as invalid, then.
Comment 4 Andrei Alexandrescu 2012-01-19 12:39:17 UTC
Cool, this is going to make for some interesting plays :o).