Skip to content

Commit

Permalink
Fix Issue 18913 - Cannot move static array of non-copyable type
Browse files Browse the repository at this point in the history
  • Loading branch information
edi33416 committed Dec 19, 2018
1 parent 21afd40 commit a3fdf76
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion std/algorithm/mutation.d
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ void moveEmplace(T)(ref T source, ref T target) @system
import core.stdc.string : memcpy, memset;
import std.traits : hasAliasing, hasElaborateAssign,
hasElaborateCopyConstructor, hasElaborateDestructor,
isAssignable;
isAssignable, isStaticArray;

static if (!is(T == class) && hasAliasing!T) if (!__ctfe)
{
Expand Down Expand Up @@ -1418,6 +1418,11 @@ void moveEmplace(T)(ref T source, ref T target) @system
}
}
}
else static if (isStaticArray!T)
{
for (size_t i = 0; i < source.length; ++i)
move(source[i], target[i]);
}
else
{
// Primitive data (including pointers and arrays) or class -
Expand Down Expand Up @@ -1451,6 +1456,24 @@ pure nothrow @nogc @system unittest
assert(val == 0);
}

// issue 18913
@safe unittest
{
static struct NoCopy
{
int payload;
~this() { }
@disable this(this);
}

static void f(NoCopy[2]) { }

NoCopy[2] ncarray = [ NoCopy(1), NoCopy(2) ];

static assert(!__traits(compiles, f(ncarray)));
f(move(ncarray));
}

// moveAll
/**
Calls `move(a, b)` for each element `a` in `src` and the corresponding
Expand Down

0 comments on commit a3fdf76

Please sign in to comment.