DMD 1.001 release is broken
Lionello Lunesu
lio at lunesu.remove.com
Thu Jan 25 23:58:15 PST 2007
Walter Bright wrote:
> Frits van Bommel wrote:
>> 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...
>
> I believe this fails with C++, too. But I don't think there's any
> solution to it but completely disable NRVO. There's no reasonable way
> for the compiler to detect that the d's are aliased. But NRVO is too
> valuable an optimization. So instead I'll argue that this is akin to:
> i = i++;
> i.e. it's an order-of-evaluation issue that should be avoided.
This still fails:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=46576
(it's also in bugzilla, issue 829)
There's no "inout", just:
struct Vector3 {
//....
Vector3 opMul(float s)
{
Vector3 ret;
ret.x = x*s;
ret.y = y*s;
ret.z = z*s;
return ret;
}
}
Vector3 a;
a.set(1,1,1);
a = a*2;
// a will be nan,nan,nan
Where did those nans come from? Must be the initializers from the return
value "ret".
L.
More information about the Digitalmars-d-announce
mailing list