From fb8bb7652ff9b2fe6c40f7d97a65d6445c873971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 15 Apr 2024 19:04:24 +0200 Subject: [PATCH] Silence deprecation warning for accessing overlapping pointer data in safe code. --- source/taggedalgebraic/taggedunion.d | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index 34b3d5f..4827b1b 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -58,13 +58,14 @@ align(commonAlignment!(UnionKindTypes!(UnionFieldEnum!U))) struct TaggedUnion private { static if (isUnitType!(FieldTypes[0]) || __VERSION__ < 2072) { void[Largest!FieldTypes.sizeof] m_data; + @property ref inout(void[Largest!FieldTypes.sizeof]) rawData() inout @safe return { return m_data; } } else { union Dummy { FieldTypes[0] initField; void[Largest!FieldTypes.sizeof] data; - alias data this; } Dummy m_data = { initField: FieldTypes[0].init }; + @property ref inout(void[Largest!FieldTypes.sizeof]) rawData() inout @trusted return { return m_data.data; } } Kind m_kind; } @@ -319,7 +320,7 @@ align(commonAlignment!(UnionKindTypes!(UnionFieldEnum!U))) struct TaggedUnion { if (m_kind != kind) { destroy(this); - m_data.rawEmplace(value); + this.rawData.rawEmplace(value); } else { rawSwap(trustedGet!(FieldTypes[kind]), value); } @@ -373,7 +374,7 @@ align(commonAlignment!(UnionKindTypes!(UnionFieldEnum!U))) struct TaggedUnion } } - package @trusted @property ref inout(T) trustedGet(T)() inout { return *cast(inout(T)*)m_data.ptr; } + package @trusted @property ref inout(T) trustedGet(T)() inout { return *cast(inout(T)*)this.rawData.ptr; } } }