@@ -27,24 +27,21 @@ Tarr _d_arrayctor(Tarr : T[], T)(return scope Tarr to, scope Tarr from) @trusted
27
27
import core.internal.traits : hasElaborateCopyConstructor, Unqual;
28
28
import core.lifetime : copyEmplace;
29
29
import core.stdc.string : memcpy;
30
+ import core.stdc.stdint : uintptr_t ;
30
31
debug (PRINTF ) import core.stdc.stdio ;
31
32
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
-
41
33
debug (PRINTF ) printf(" _d_arrayctor(to = %p,%d, from = %p,%d) size = %d\n " , from.ptr, from.length, to.ptr, to.length, T.tsize);
42
34
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.
45
37
void [] vFrom = (cast (void * )from.ptr)[0 .. from.length];
46
38
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" );
48
45
49
46
static if (hasElaborateCopyConstructor! T)
50
47
{
0 commit comments