Regression in 2.060 - corruption when lambda closes over foreach variable

Ben Davis entheh at cantab.net
Sun Sep 16 16:18:12 PDT 2012


Sorry, the second "I'm compiling with" is a lie. (Edited it out below.)

On 17/09/2012 00:16, Ben Davis wrote:
> Hi,
>
> I have some code which has started breaking as of 2.060. I've simplified
> it down to the following:
>
> ------------
>
> import std.stdio;
>
> void main() {
>      broken();
>      reffix();
>      noclosefix();
> }
>
> void broken() {
>      foreach (z; 0..1) {
>          writeln(z);    //Corrupt
>          () {writeln(z);} ();    //Corrupt (same)
>      }
> }
>
> //Adding 'ref' fixes it:
> void reffix() {
>      foreach (ref z; 0..1) {
>          writeln(z);    //0
>          () {writeln(z);} ();    //0
>      }
> }
>
> //It only breaks if 'z' is closed into the lambda:
> void noclosefix() {
>      foreach (z; 0..1) {
>          writeln(z);    //0
>          int z2=z;
>          () {writeln(z2);} ();    //0
>      }
> }
>
> ------------
>
> The sort of corrupt values I see for z are for example
> 28835840 = 0x01B80000
> 29949952 = 0x01C90000
> 38535168 = 0x024C0000
> 36110336 = 0x02270000
> But it's always the same between one writeln and the other.
>
> Also breaks with foreach_reverse.
>
> I'm compiling with no switches at all, just "dmd filename.d".
>
> Anyone fancy taking a look?
>
> Thanks,
>
> Ben :)



More information about the Digitalmars-d mailing list