Skip to content

Commit

Permalink
Fix Bugzilla 24872 - Assigning non-copyable value to array has no effect
Browse files Browse the repository at this point in the history
  • Loading branch information
pbackus committed Nov 22, 2024
1 parent 3fa3ac8 commit e13c618
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion druntime/src/core/internal/array/arrayassign.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit e13c618

Please sign in to comment.