@@ -27,24 +27,21 @@ Tarr _d_arrayctor(Tarr : T[], T)(return scope Tarr to, scope Tarr from) @trusted
2727 import core.internal.traits : hasElaborateCopyConstructor, Unqual;
2828 import core.lifetime : copyEmplace;
2929 import core.stdc.string : memcpy;
30+ import core.stdc.stdint : uintptr_t ;
3031 debug (PRINTF ) import core.stdc.stdio ;
3132
32- // Force `enforceRawArraysConformable` to be `pure`
33- void enforceRawArraysConformable (const char [] action, const size_t elementSize, const void [] a1, const void [] a2, in bool allowOverlap = false ) @trusted
34- {
35- import core.internal.util.array : enforceRawArraysConformable;
36-
37- alias Type = void function (const char [] action, const size_t elementSize, const void [] a1, const void [] a2, in bool allowOverlap = false ) pure nothrow ;
38- (cast (Type)&enforceRawArraysConformable)(action, elementSize, a1, a2, allowOverlap);
39- }
40-
4133 debug (PRINTF ) printf(" _d_arrayctor(to = %p,%d, from = %p,%d) size = %d\n " , from.ptr, from.length, to.ptr, to.length, T.tsize);
4234
43- auto element_size = T.sizeof;
44-
35+ // Rewrite `enforceRawArraysConformable` manually to allow @nogc.
36+ // Use more austere errors because @nogc doesn't allow string concatenation.
4537 void [] vFrom = (cast (void * )from.ptr)[0 .. from.length];
4638 void [] vTo = (cast (void * )to.ptr)[0 .. to.length];
47- enforceRawArraysConformable(" initialization" , element_size, vFrom, vTo, false );
39+ assert (vFrom.length == vTo.length, " Array lengths don't match" );
40+
41+ const ptrTo = cast (uintptr_t )vTo.ptr;
42+ const ptrFrom = cast (uintptr_t )vFrom.ptr;
43+ const d = ptrTo > ptrFrom ? ptrTo - ptrFrom : ptrFrom - ptrTo;
44+ assert (d >= vFrom.length * T.sizeof, " Overlapping arrays" );
4845
4946 static if (hasElaborateCopyConstructor! T)
5047 {
0 commit comments