On 06/21/2014 11:56 AM, "Marc Schütz" <schue...@gmx.net>" wrote:

>      import std.stdio;
>
>      struct A {
>          this(this) {
>              writeln("A.this(this)");
>          }
>
>          B b1, b2;
>      }
>
>      struct B {
>          this(this) {
>              writeln("B.this(this)");
>          }
>      }
>
>      void main() {
>          A a, b;
>          a = b;
>      }
>
> This outputs:
>
>      B.this(this)
>      B.this(this)
>      A.this(this)
>
> Now, http://dlang.org/struct.html#AssignOverload says:
>
>      ref S opAssign(S s)
>      {

Note that opAssign takes by-value. The post-blits that you see are due that copy. i.e. b in main is copied to the argument that opAssign sees.

Also note that if the right-hand side in main() were an rvalue, then that copy would not involve any post-blit.

>        S tmp = this;   // bitcopy this into tmp
>        this = s;       // bitcopy s into this
>        tmp.__dtor();   // call destructor on tmp
>        return this;
>      }
>
> Note the term "bitcopy", which for me implies that no postblits are
> supposed to be called.
>
> What the compiler does makes sense to me, but it seems to contradict the
> documentation. I guess the call to the postblit is missing in the
> pseudo-code... Am I right?
>
> (DMD git 514db2e212ae52e1206d4296e48d4a689370d04b)

Ali

Reply via email to