On Fri, 17 Jun 2011 06:42:51 -0400, Steven Schveighoffer <schvei...@yahoo.com> wrote:

On Fri, 17 Jun 2011 00:05:56 -0400, Jose Armando Garcia <jsan...@gmail.com> wrote:

It looks like the rt is not calling the postblit constructor when
concatenating arrays. For example, the following code:

import std.stdio;

struct Test
{
   this(this) { writeln("copy done"); }
   void opAssign(Test rhs) { writeln("assignment done"); }
   ~this() { writeln("destructor called"); }
}

void main()
{
   Test[] tests = new Test[1];
   {
      Test test;
      tests ~= test;
   }
   writeln("done");
}

Gives the following output:

destructor called
done

The dtr for 'Test test;' is getting call after the scope exits but the
postblit ctr for 'tests[0]' is never called. I believe the output of
this code should either be:

done

or:

copy done
destructor called
done


You are right, postblit should be called. http://d.puremagic.com/issues/show_bug.cgi?id=5272

I'll look at doing a fix.

https://github.com/D-Programming-Language/druntime/pull/29

See if that helps. On my system, your code now results in your expected output.

-Steve

Reply via email to