From ba79a252983fd8d0f231483766200da8ae987c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 16 Apr 2019 10:09:27 +0200 Subject: [PATCH] Add explicit unit test for commonAlignment. --- source/taggedalgebraic/taggedunion.d | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index 22b8059..49803bc 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -791,6 +791,21 @@ private size_t commonAlignment(TYPES...)() return ret; } +unittest { + align(2) struct S1 { ubyte x; } + align(4) struct S2 { ubyte x; } + align(8) struct S3 { ubyte x; } + + static if (__VERSION__ > 2076) { // DMD 2.076 ignores the alignment + assert(commonAlignment!S1 == 2); + assert(commonAlignment!S2 == 4); + assert(commonAlignment!S3 == 8); + assert(commonAlignment!(S1, S3) == 8); + assert(commonAlignment!(S1, S2, S3) == 8); + assert(commonAlignment!(S2, S2, S1) == 4); + } +} + package void rawEmplace(T)(void[] dst, ref T src) { T[] tdst = () @trusted { return cast(T[])dst[0 .. T.sizeof]; } ();