From 4c645bbaf970985f9d30e25a4b8f7bdd39b765ef Mon Sep 17 00:00:00 2001 From: Paul Backus Date: Fri, 22 Nov 2024 14:03:09 -0500 Subject: [PATCH] Fix Bugzilla 24872 - Assigning non-copyable value to array has no effect --- druntime/src/core/internal/array/arrayassign.d | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/druntime/src/core/internal/array/arrayassign.d b/druntime/src/core/internal/array/arrayassign.d index 6e3c1fdc3eff..21690caf5d94 100644 --- a/druntime/src/core/internal/array/arrayassign.d +++ b/druntime/src/core/internal/array/arrayassign.d @@ -347,7 +347,7 @@ Tarr _d_arraysetassign(Tarr : T[], T)(return scope Tarr to, scope ref T value) @ static if (__traits(isCopyable, T)) copyEmplace(value, dst); else - memcpy(cast(void*) &value, cast(void*) &dst, elemSize); + memcpy(cast(void*) &dst, cast(void*) &value, elemSize); auto elem = cast(Unqual!T*) &tmp; destroy(*elem); } @@ -395,6 +395,20 @@ Tarr _d_arraysetassign(Tarr : T[], T)(return scope Tarr to, scope ref T value) @ assert(arr == [S(1234), S(1234), S(1234), S(1234)]); } +// disabled copy constructor +@safe unittest +{ + static struct S + { + int val; + @disable this(ref S); + } + S[1] arr; + S s = S(1234); + _d_arraysetassign(arr[], s); + assert(arr[0].val == 1234); +} + // throwing and `nothrow` @safe nothrow unittest {