On Thursday, 3 January 2013 at 18:36:32 UTC, Jonathan M Davis wrote:
On Thursday, January 03, 2013 17:59:22 deadalnix wrote:
On Thursday, 3 January 2013 at 16:43:06 UTC, bearophile wrote:
> deadalnix:
>> I still have code broken all over the place.
> > D2 is getting its corner case problems sorted out and fixed,
> but this still causes some breakage in user code. As more
> people use D2, issues are found, discussed and fixed, the
> breakages will get more and more uncommon.

Is this breakage intended ? To me it doesn't make sense, the
generated code is :

(Bar bar = Bar.init; , bar).this()

It is most definitely intended. ref requires an lvalue. A struct literal is a
temporary and therefore should be an rvalue, not an lvalue.


struct Bar {
        uint i;

        this(uint foo) {
                import std.stdio;
                writeln(&this);
        }
}

void main() {
        Bar(0);
}

Before, you had the stupid situation of

foo(Bar()); //compiles
foo(funcWhichReturnsBar()); //fails to compile

Both are dealing with temporaries, so both should be rvalues, and neither should compile. You need an actual variable or other non-temporary memory location (e.g. dereferenced pointer) if you want to pass an argument to a ref function. The previous behavior was broken and should have been fixed ages ago.

- Jonathan M Davis

The compiler actually create this storage to pass it to the constructor. Why can't it pass it to something else ?

Reply via email to