Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Closed
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
26 changes: 24 additions & 2 deletions src/core/atomic.d
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,23 @@ TailShared!T atomicLoad(MemoryOrder ms = MemoryOrder.seq, T)(ref shared const T
* newval = The value to store.
*/
void atomicStore(MemoryOrder ms = MemoryOrder.seq, T, V)(ref T val, V newval) pure nothrow @nogc @trusted
if (!is(T == shared) && !is(V == shared))
if (!is(T == shared) && !is(V == shared) && is(T : V))
{
import core.internal.traits : hasElaborateCopyConstructor;
static assert (!hasElaborateCopyConstructor!T, "`T` may not have an elaborate copy: atomic operations override regular copying semantics.");

// resolve implicit conversions
T arg = newval;
import core.internal.traits : Unqual;
static if (is(Unqual!T == Unqual!V))
{
alias arg = newval;
}
else
{
// don't construct directly from `newval`, assign instead (`alias this` etc.)
T arg;
arg = newval;
}

static if (__traits(isFloating, T))
{
Expand Down Expand Up @@ -1194,4 +1204,16 @@ version (CoreUnittest)
shared NoIndirections n;
static assert(is(typeof(atomicLoad(n)) == NoIndirections));
}

unittest
{
static struct S
{
int a;
alias a this;
}

S s;
atomicStore(s, 123);
}
}