From 3032c149185c2858fa0a2b88171afc18fec981e8 Mon Sep 17 00:00:00 2001 From: Nicholas Lindsay Wilson Date: Tue, 21 Apr 2020 18:37:50 +0800 Subject: [PATCH 1/4] [core.atomic] atomicStore for alias this --- src/core/atomic.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/atomic.d b/src/core/atomic.d index 512cf6563a..10a3b3aca2 100644 --- a/src/core/atomic.d +++ b/src/core/atomic.d @@ -116,7 +116,17 @@ void atomicStore(MemoryOrder ms = MemoryOrder.seq, T, V)(ref T val, V newval) pu 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)) { From 623a95a36f8da6934b6be10983a2ffb4fa72d5a5 Mon Sep 17 00:00:00 2001 From: Nicholas Lindsay Wilson Date: Tue, 21 Apr 2020 20:10:56 +0800 Subject: [PATCH 2/4] Add unittest --- src/core/atomic.d | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/atomic.d b/src/core/atomic.d index 10a3b3aca2..49368cd6a4 100644 --- a/src/core/atomic.d +++ b/src/core/atomic.d @@ -1204,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); + } } From 1e525714f87238fb928527fba337813ec41eaf5d Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Tue, 31 Aug 2021 18:20:06 +0800 Subject: [PATCH 3/4] Update atomic.d --- src/core/atomic.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/atomic.d b/src/core/atomic.d index 49368cd6a4..330ea32ca0 100644 --- a/src/core/atomic.d +++ b/src/core/atomic.d @@ -110,7 +110,7 @@ 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(V : T)) { import core.internal.traits : hasElaborateCopyConstructor; static assert (!hasElaborateCopyConstructor!T, "`T` may not have an elaborate copy: atomic operations override regular copying semantics."); From 8b3ebdee293ce6e779df5a489ebc65b2485f195f Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Tue, 21 Sep 2021 20:50:46 +0800 Subject: [PATCH 4/4] fix ordering of `is(T:V)` --- src/core/atomic.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/atomic.d b/src/core/atomic.d index 330ea32ca0..60f5601d66 100644 --- a/src/core/atomic.d +++ b/src/core/atomic.d @@ -110,7 +110,7 @@ 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) && is(V : T)) + 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.");