<div dir="ltr"><div>At least there's a dmd bug.</div><div><br></div><div>For such static array assignment, dmd should use druntime function, but instead plain memory copy operation used.</div><div><a href="https://github.com/D-Programming-Language/dmd/blob/master/src/e2ir.c#L2920">https://github.com/D-Programming-Language/dmd/blob/master/src/e2ir.c#L2920</a><br></div><div><a href="https://github.com/D-Programming-Language/dmd/blob/master/src/e2ir.c#L2945">https://github.com/D-Programming-Language/dmd/blob/master/src/e2ir.c#L2945</a><br></div><div><br></div><div>And, even after the bug is fixed, I think it's debatable behavior whether an element-wise assignment should call opAssign on each elements, because it can be a kind of optimization.</div><div><br></div>Related issue: <a href="https://issues.dlang.org/show_bug.cgi?id=8931">https://issues.dlang.org/show_bug.cgi?id=8931</a><div><br></div><div>Kenji Hara<br><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-20 23:18 GMT+09:00 David Nadlinger via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I was about to fix an issue with postblits/destructors in LDC when I stumbled upon the following vexing behaviour in DMD (both 2.067.1 and master):<br>
<br>
---<br>
uint dtorCount;<br>
<br>
struct S {<br>
    uint x;<br>
    void opAssign(const ref S rhs) { assert(false, "Not called"); }<br>
    ~this() { ++dtorCount; }<br>
}<br>
<br>
<br>
void main() {<br>
    S[2] a;<br>
    a[0].x = 42;<br>
<br>
    a = a.init;<br>
<br>
    assert(a[0].x == 0); // as expected the value has been reset<br>
    assert(dtorCount == 0); // Passes?!?<br>
}<br>
---<br>
<br>
I would have expected this to either call opAssign or to destruct the instance, blit the init value, and call any postblits. However, as you can see neither the dtor nor opAssign are executed. If I add a postblit to S, then suddenly the dtor is invoked too.<br>
<br>
Am I missing something here, or is this a major bug in struct lifetime handling?<br>
<br>
I understand why this happens from the DMD source, but it almost seems like it was deliberately written this way; thus the question.<span class="HOEnZb"><font color="#888888"><br>
<br>
 — David<br>
</font></span></blockquote></div><br></div>