Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bugzilla 24872 - Assigning non-copyable value to array has no effect #17083

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading