From 1bd9b79e8462d03e382b53dda6f297e4e75eb6f0 Mon Sep 17 00:00:00 2001 From: k-hara Date: Thu, 31 May 2012 10:35:45 +0900 Subject: [PATCH] fix Issue 8171 - Broken std.algorithm.move for nested struct has no member --- std/algorithm.d | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/std/algorithm.d b/std/algorithm.d index a035e8302..3c4857800 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -1352,7 +1352,8 @@ void move(T)(ref T source, ref T target) static if (hasElaborateDestructor!T || hasElaborateCopyConstructor!T) { static T empty; - static if (T.tupleof[$-1].stringof.endsWith("this")) + static if (T.tupleof.length > 0 && + T.tupleof[$-1].stringof.endsWith("this")) { // If T is nested struct, keep original context pointer memcpy(&source, &empty, T.sizeof - (void*).sizeof); @@ -1443,7 +1444,8 @@ T move(T)(ref T source) static if (hasElaborateDestructor!T || hasElaborateCopyConstructor!T) { static T empty; - static if (T.tupleof[$-1].stringof.endsWith("this")) + static if (T.tupleof.length > 0 && + T.tupleof[$-1].stringof.endsWith("this")) { // If T is nested struct, keep original context pointer memcpy(&source, &empty, T.sizeof - (void*).sizeof); @@ -1557,6 +1559,19 @@ unittest// Issue 8057 a.x = 1; auto b = foo(a); assert(b.x == 1); + + // Regression 8171 + static struct Array(T) + { + // nested struct has no member + struct Payload + { + ~this() {} + } + } + Array!int.Payload x = void; + static assert(__traits(compiles, move(x) )); + static assert(__traits(compiles, move(x, x) )); } // moveAll