Share via


Another good customer bug

Reader Andy Neilson writes in with another bug:

The current compiler implementation has some problems. If the variable is a field of this, then the compiler will die. For example:

class MyClass {
public:
int i;

void Foo() {
array<int>^ x = {1, 2, 3};

for each (i in x) {
if (i == 2) break;
}
}
};

This is also a bug. I'll file it in our bug tracking database. I'm not sure what the design decision will be; it feels like we should disallow the construct you show - but I'm not certain. I found a "sort-of" workaround; you can use a tracking reference to an integer to do it, such as:

void Foo() {
array<int>^ x = {1, 2, 3};
int% a = i;
for each (a in x) {
...
}
}

Thanks for the bug report!

Comments