<div>------------------------------</div><div><div>import std.stdio;</div><div><br></div><div>struct Test {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>this( this ) { writeln( "Test.this(this)" ); }</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>~this() { writeln( "Test.~this()" ); }</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>void opAssign( Test rhs ) { writeln( "Test.opAssign" ); }</div>
<div>}</div><div><br></div><div>ref Test makeRef( ref Test test ) { return test; }</div><div><br></div><div>int main(string[] argv) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Test x,y;</div>
<div>
<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>writeln( "Before assignment" );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>x = makeRef(y);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>writeln( "After assignment" );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>readln();</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>return 0;</div><div>}</div></div><div><br></div><div><br></div><div>------------------------------</div><div>Output:</div><div><br></div><div>Before assignment</div>
<div>Test.opAssign</div><div>Test.~this()</div><div>After assignment</div><div>Test.~this()</div><div>Test.~this()</div><div>------------------------------</div><div><br></div><div>The code above assigns a reference to a Test object to another Test object. The assignment doesn't call the postblit constructor, yet it calls the destructor (lines 2,3 in the output). Changing the assignment to "x = y;" makes it call the postblit.</div>
<div>Is this correct behaviour, or should I file it as a bug?</div><div><br></div><div>---</div>Cristi Cobzarenco<div>BSc in Artificial Intelligence and Computer Science</div><div>University of Edinburgh<br>Profile: <a href="http://www.google.com/profiles/cristi.cobzarenco" target="_blank">http://www.google.com/profiles/cristi.cobzarenco</a></div>
<br>