mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
fix Issue 8171 - Broken std.algorithm.move for nested struct has no member
This commit is contained in:
parent
c164f04018
commit
1bd9b79e84
1 changed files with 17 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue