<div dir="ltr"><div>This is definitely a bug.<br></div><div><br></div><div><a href="http://d.puremagic.com/issues/show_bug.cgi?id=9907">http://d.puremagic.com/issues/show_bug.cgi?id=9907</a> <br></div><div class="gmail_extra">
<br></div><div class="gmail_extra">Kenji Hara<br><br><div class="gmail_quote">2013/4/9 Ali Çehreli <span dir="ltr"><<a href="mailto:acehreli@yahoo.com" target="_blank">acehreli@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 04/08/2013 12:24 PM, Maxim Fomin wrote:<br>
<br>
> DMD often inserts temporaries when they are unexpected (or users do not<br>
> expect when they should).<br>
><br>
> D main function in destructor case is rewritten as:<br>
><br>
>     S s = S(1);<br>
>     s.opAssign(foo(2));<br>
>     s.opAssign((S __sl1779 = S(3); , __sl1779))<br>
<br></div>
Have you manually typed those lines or is there a tool that outputs that "preprocessor" ;) output?<div class="im"><br>
<br>
><br>
> Hence, ref version is taken in account because '__sl1779' is a good lvalue.<br>
><br>
> Troubles seems to come from<br>
> <a href="https://github.com/D-Programming-Language/dmd/blob/master/src/expression.c#L4203" target="_blank">https://github.com/D-<u></u>Programming-Language/dmd/blob/<u></u>master/src/expression.c#L4203</a> <br>
><br>
<br></div>
Thank you very much for finding the related line. :) Quoting:<br>
<br>
Expression *StructLiteralExp::semantic(<u></u>Scope *sc)<br>
{ Expression *e;<br>
<br>
// ...<br>
<br>
    /* If struct requires a destructor, rewrite as:<br>
     * (S tmp = S()),tmp<br>
     * so that the destructor can be hung on tmp.<br>
     */<br>
    if (sd->dtor && sc->func)<br>
    {<br>
        Identifier *idtmp = Lexer::uniqueId("__sl");<br>
        VarDeclaration *tmp = new VarDeclaration(loc, type, idtmp, new ExpInitializer(0, this));<br>
        tmp->storage_class |= STCctfe;<br>
        Expression *ae = new DeclarationExp(loc, tmp);<br>
        Expression *e = new CommaExp(loc, ae, new VarExp(loc, tmp));<br>
        e = e->semantic(sc);<br>
        return e;<br>
    }<br>
<br>
    return this;<br>
}<br>
<br>
Is it because destructors cannot be "hung" on literals?<br>
<br>
It is inconsistent that function-returned rvalues do not behave the same as literal-rvalues.<span class="HOEnZb"><font color="#888888"><br>
<br>
Ali<br>
<br>
</font></span></blockquote></div><br></div></div>