February 28, 2011 [Issue 5661] New: std.algorithm.move does not work on elaborate struct | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=5661 Summary: std.algorithm.move does not work on elaborate struct Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: major Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: k.hara.pg@gmail.com --- Comment #0 from Kenji Hara <k.hara.pg@gmail.com> 2011-02-27 21:30:08 PST --- Created an attachment (id=924) testcase std.algorithm.move does not work on T that hasElaborateDestructor!T or hasElaborateCopyConstructor!T. This test should work. ---- unittest { static struct S { static struct X { int n = 0; ~this(){n = 0;} } X x; } static assert(hasElaborateDestructor!S); S s1, s2; s1.x.n = 1; move(s1, s2); assert(s1.x.n == 0); assert(s2.x.n == 1); static struct T { static struct X { int n = 0; this(this){n = 0;} } X x; } static assert(hasElaborateCopyConstructor!T); T t1, t2; t1.x.n = 1; move(t1, t2); assert(t1.x.n == 0); assert(t2.x.n == 1); } ---- See also attached file of full test case. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 28, 2011 [Issue 5661] std.algorithm.move does not work on elaborate struct | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kenji Hara | http://d.puremagic.com/issues/show_bug.cgi?id=5661 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch --- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-02-27 21:31:26 PST --- Following patch fixes this bug: std/algorithm.d | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/std/algorithm.d b/std/algorithm.d index 0a1e496..ed05c85 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -1057,11 +1057,11 @@ void move(T)(ref T source, ref T target) { // Most complicated case. Destroy whatever target had in it // and bitblast source over it - static if (is(typeof(target.__dtor()))) target.__dtor(); + static if (hasElaborateDestructor!T) typeid(T).destroy(&target); memcpy(&target, &source, T.sizeof); // If the source defines a destructor or a postblit hook, we must obliterate the // object in order to avoid double freeing and undue aliasing - static if (is(typeof(source.__dtor())) || is(typeof(source.__postblit()))) + static if (hasElaborateDestructor!T || hasElaborateCopyConstructor!T) { static T empty; memcpy(&source, &empty, T.sizeof); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation