← Back to index
|
Original Bugzilla link
Bug 3154 – foreach corrupting data returned by ref functions.
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-07-08T13:43:00Z
Last change time
2015-06-09T01:28:06Z
Keywords
wrong-code
Assigned to
nobody
Creator
kovrov+puremagic
Comments
Comment #0
by kovrov+puremagic — 2009-07-08T13:43:11Z
void main() { auto test = Foo(3); foreach (i; test.items) { } } struct Foo { struct Generator { int opApply(int delegate(ref long) dg) { const bak = this.foo.data; // control copy int res; for (long i=0; i < bak; i++) { assert (bak == this.foo.data, "this.foo changed?!"); res = dg(i); if (res) break; } return res; } Foo foo; } ref Generator items() // ref is important { return Generator(this); // Generator.foo = this } int data; }
Comment #1
by clugdbug — 2010-05-06T23:53:17Z
Fixed DMD 2.034.