DMD 1.001 release is broken

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Jan 25 02:09:11 PST 2007


Walter Bright wrote:
> Chris Miller wrote:
>> I think there may also be something wrong with NRVO (Named Return 
>> Value Optimization). Many of my projects just ended up with broken 
>> features until I downgraded to DMD 0.177. I was able to find a 
>> workaround for one of the things it broke by using an inout parameter 
>> instead of returning a struct, but other things were too broken in 
>> that project so I still had to downgrade DMD. I don't have 
>> reproducable examples, it took me long enough just to track down and 
>> confirm that one issue with the workaround.
> 
> I need a test case. The ones I have all work.

Here's one that fails (tested on DMD v1.00, v1.002):

-----
import std.stdio;

struct Data
{
     int x, y;

     /// To make size > 8 so NRVO is used.
     /// Program runs correctly with this line commented out:
     byte filler;
}

Data frob(inout Data d)
{
     Data ret;
     ret.y = d.x - d.y;
     ret.x = d.x + d.y;
     return ret;
}

void main() {
     Data d; d.x = 1; d.y = 2;
     d = frob(d);
     writefln(d.x);
     writefln(d.y);
     assert(d.x == 3 && d.y == -1);
}
-----

The problem here is return value/parameter aliasing. It initializes the 
return value before even looking at the parameter...



More information about the Digitalmars-d-announce mailing list