From 515bf619e8eea223593f2c465d412405e2909374 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 1 Sep 2017 19:38:44 +0200 Subject: [PATCH] Add support for dmd 2.076.0 --- .travis.yml | 3 +- appveyor.yml | 6 ++++ source/tanya/meta/trait.d | 60 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 176c2a0..84a483c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ os: language: d d: + - dmd-2.076.0 - dmd-2.075.1 - dmd-2.074.1 - dmd-2.073.2 @@ -22,7 +23,7 @@ addons: - gcc-multilib before_script: - - if [ "$PS1" = '(dmd-2.075.1)' ]; then + - if [ "$PS1" = '(dmd-2.076.0)' ]; then export UNITTEST="unittest-cov"; fi diff --git a/appveyor.yml b/appveyor.yml index 1eee97f..5c52adb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,12 @@ os: Visual Studio 2015 environment: matrix: + - DC: dmd + DVersion: 2.076.0 + arch: x64 + - DC: dmd + DVersion: 2.076.0 + arch: x86 - DC: dmd DVersion: 2.075.1 arch: x64 diff --git a/source/tanya/meta/trait.d b/source/tanya/meta/trait.d index 697673f..6587fa2 100644 --- a/source/tanya/meta/trait.d +++ b/source/tanya/meta/trait.d @@ -209,6 +209,23 @@ pure nothrow @safe @nogc unittest static assert(sizeOf!(void[16]) == 16); } +/** + * Returns the alignment of the type $(D_PARAM T). + * + * Params: + * T = A type. + * + * Returns: Alignment of the type $(D_PARAM T). + */ +enum size_t alignOf(T) = T.alignof; + +/// +pure nothrow @safe @nogc unittest +{ + static assert(alignOf!bool == bool.alignof); + static assert(is(typeof(alignOf!bool) == typeof(bool.alignof))); +} + /** * Tests whether $(D_INLINECODE Args[0]) and $(D_INLINECODE Args[1]) are the * same symbol. @@ -396,7 +413,8 @@ version (TanyaPhobos) hasElaborateDestructor, hasElaborateCopyConstructor, hasElaborateAssign, - EnumMembers; + EnumMembers, + classInstanceAlignment; } else: @@ -2627,3 +2645,43 @@ pure nothrow @nogc @safe unittest } static assert([E.one, E.two, E.three] == [ EnumMembers!E ]); } + +/** + * Different than $(D_INLINECODE T.alignof), which is the same for all class + * types, $(D_PSYMBOL classInstanceOf) determines the alignment of the class + * instance and not of its reference. + * + * Params: + * T = A class. + * + * Returns: Alignment of an instance of the class $(D_PARAM T). + */ +template classInstanceAlignment(T) +if (is(T == class)) +{ + private enum ptrdiff_t pred(U1, U2) = U1.alignof - U2.alignof; + private alias Fields = typeof(T.tupleof); + enum size_t classInstanceAlignment = Max!(pred, T, Fields).alignof; +} + +/// +pure nothrow @safe @nogc unittest +{ + class C1 + { + } + static assert(classInstanceAlignment!C1 == C1.alignof); + + struct S + { + align(8) + uint s; + + int i; + } + class C2 + { + S s; + } + static assert(classInstanceAlignment!C2 == S.alignof); +}