Question

According to the section "Foreach Restrictions" at http://dlang.org/statement.html the following code

int[] a;
int[] b;
foreach (int i; a) { 
    a = null; // error
    a.length += 10; // error 
    a = b; // error 
}
a = null; // ok

should error.

But it doesn't for me when using 2.063.2 nor master.

Is this a regression bug?

Was it helpful?

Solution

It was probably never implemented as an actual error. I don't see an open bug, but I'm bad at searching bugzilla... regardless though, I'm sure the spec simply was never implemented to actually show the error, leaving it as undefined behavior if you actually do it.

OTHER TIPS

In several places, the D documentation says something is an error, without the compiler actually checking for this. C and C++ would probably use the term 'undefined behavior' instead of 'error'. In C and C++, such a program is valid, you just have no idea what it does. In D, it is simply not considered a valid program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top