While working on my project, I ran into a very hard to trace bug that I finally managed to isolate and reproduce on a small scale.<div><br></div><div>The code:</div><div><br></div><div><div><div>import std.stdio;</div><div>
import std.conv;</div><div><br></div><div>struct Test {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>int x;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>this( int m ) { x = m; }</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>this( this ) { writeln( "Postblit: ", x ); }</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>~this() { x = 42; }</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>string toString() { return to!string( x ); }</div><div>}</div><div><br></div><div>
int main(string[] argv) {</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>auto a = Test(3);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>writeln( a );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return 0;</div>
<div>}</div></div></div><div><br></div><div>Prints 42 on my computer, instead of 3. The writeln in the postblit constructor shows that the object is copied 6 times, and only on the last copy x becomes 42 instead of 3. Somehow the destructor gets called on an object before it is copied. The copying that causes the problem is in format.d@1599 as far as I can tell with my debugger.</div>
<div><br></div><div>I don't know if it's high priority for everyone, but it certainly is for me.</div><div><br></div><div><br clear="all"><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>
</div>