[Issue 6581] Yet another dtor/postblit problem?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 20 13:01:39 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6581
--- Comment #6 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2011-09-20 13:01:11 PDT ---
> > I should point out that move == swap & destroy, iff left side of assigment
> > _was_ initialized. A constructor may be called on chunk of uninitialized memory
> > e.g. in Phobos std.typecons.emplace.
>
> In B's constructor, the member a is already intialized by A.init. So `a =
> A(dummy);` is always assignment.
Example:
ubyte[B.sizeof] mem=void;
emplace!B(mem.ptr);//Does this call to B's constructor call A's dtor on some
kind of trash then?
>
> And, yes, I think using emplace is right way to *initialize* member a.
>
And that's a problem. I mean even when emplace is working and all. Do we really
want everybody to write emplace(&a, dummy); to do initialization in
constructor?
Seems very backwards.
I'd hate it if this will be some kind of rule #22 of how to do things correctly
in D.
> emplace(&a, dummy); // a is treated as an uninitialized memory
>
> But, unfortunately, emplace has a bug. This does not work as our expected.
>
>
> > why do we copying the original value in the first place?
> > It should be moved with e.g. memmov
>
> Ah... my explanation had a bit misleading. When opAssign receives rvalue, rhs
> is just moved. Otherwise, rhs is coped. In this case, A(dummy) is treated as
> rvalue, so it is moved.
Ok, glad it works this way.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list