From bd090534a41834bb4efd0fc8afb7506bb2d87f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20IRMAK?= Date: Sun, 14 Nov 2021 14:47:07 +0300 Subject: [PATCH 1/2] Add explicit default ctor for DList.PayNode Worksaround Issue 22510 (https://issues.dlang.org/show_bug.cgi?id=22510) which prevented us from using structs with explicit copy ctors with DList. --- std/container/dlist.d | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/std/container/dlist.d b/std/container/dlist.d index cc3e2e85dbc..32d56ecc733 100644 --- a/std/container/dlist.d +++ b/std/container/dlist.d @@ -196,6 +196,12 @@ struct DList(T) T _payload = T.init; + this (BaseNode _base, T _payload) + { + this._base = _base; + this._payload = _payload; + } + inout(BaseNode)* asBaseNode() inout @trusted { return &_base; From e84de9faaefc55d09e9f126615e97cf5a219d2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20IRMAK?= Date: Sun, 14 Nov 2021 17:37:52 +0300 Subject: [PATCH 2/2] Fix Issue 22511 - Add explicit copy ctor for Nullable --- std/typecons.d | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index feedf90e951..225fbbd44c1 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -2792,6 +2792,15 @@ struct Nullable(T) } } + this (ref return scope inout Nullable!T rhs) inout + { + _isNull = rhs._isNull; + if (!_isNull) + _value.payload = rhs._value.payload; + else + _value = DontCallDestructorT.init; + } + /** * If they are both null, then they are equal. If one is null and the other * is not, then they are not equal. If they are both non-null, then they are @@ -3284,11 +3293,11 @@ auto nullable(T)(T t) static struct S2 //inspired from 9404 { Nullable!int ni; - this(S2 other) + this(ref S2 other) { ni = other.ni; } - void opAssign(S2 other) + void opAssign(ref S2 other) { ni = other.ni; } @@ -9529,3 +9538,21 @@ unittest assert((a ^ true) == Ternary.no); assert((a ^ false) == Ternary.yes); } + +// https://issues.dlang.org/show_bug.cgi?id=22511 +@safe unittest +{ + static struct S + { + int b; + @disable this(this); + this (ref return scope inout S rhs) inout + { + this.b = rhs.b + 1; + } + } + + Nullable!S s1 = S(1); + Nullable!S s2 = s1; + assert(s2.get().b > s1.get().b); +}