[GSoC] Strange struct destructor-postblit-writeln interaction bug.

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Jun 22 08:24:57 PDT 2011


On 6/22/11 10:13 AM, dsimcha wrote:
> == Quote from Cristi Cobzarenco (cristi.cobzarenco at gmail.com)'s article
>> --bcaec520ef999f971804a64e04e4
>> Content-Type: text/plain; charset=ISO-8859-1
>> 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.
>> The code:
>> import std.stdio;
>> import std.conv;
>> struct Test {
>> int x;
>>   this( int m )     { x = m; }
>>   this( this )      { writeln( "Postblit: ", x ); }
>>   ~this()           { x = 42; }
>>   string toString() { return to!string( x ); }
>> }
>> int main(string[] argv) {
>>   auto a = Test(3);
>> writeln( a );
>> return 0;
>> }
>> 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 at 1599 as far as I can tell with my debugger.
>> I don't know if it's high priority for everyone, but it certainly is for me.
>
> This is definitely a pretty severe bug and I can reproduce it.  Please file a bug
> report in Bugzilla.  (http://d.puremagic.com/issues/)  It's ok to occasionally
> bring up very high priority bugs on this newsgroup, but they should **always** be
> filed in Bugzilla as well because otherwise they get forgotten.

Please put [GSoC] in the title.

Andrei


More information about the Digitalmars-d mailing list