From d19c437da9964e30ecdd950f62f47d091a32a58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Sun, 29 Aug 2021 02:52:09 +0100 Subject: [PATCH] std.typecons: make Nullable payload void initialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Ferreira --- std/typecons.d | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index feedf90e9..2f79a2413 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -2762,7 +2762,11 @@ struct Nullable(T) { private union DontCallDestructorT { - T payload; + import std.traits : hasIndirections; + static if (hasIndirections!T) + T payload; + else + T payload = void; } private DontCallDestructorT _value = DontCallDestructorT.init; @@ -3020,7 +3024,7 @@ struct Nullable(T) if (_isNull) { - // trusted since payload is known to be T.init here. + // trusted since payload is known to be uninitialized. () @trusted { moveEmplace(copy.payload, _value.payload); }(); } else