[Bug 226] Union alignof is less than the alignof for each of its fields

via D.gnu d.gnu at puremagic.com
Sat May 21 01:42:56 PDT 2016


http://bugzilla.gdcproject.org/show_bug.cgi?id=226

--- Comment #4 from thomas.bockman at gmail.com ---
I found a workaround:
---
struct Foo(A, B)
{
    align(max(A.sizeof, B.sizeof)) union
    {
        A a;
        B b;
    }

    static assert (typeof(this).sizeof  >= max(A.sizeof,  B.sizeof));
    static assert (typeof(this).alignof >= max(A.alignof, B.alignof));
}
---
It would need Kenji's "align(n) with n compile-time constant" PR to work
without string mixins, though:
    https://github.com/dlang/dmd/pull/5750

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the D.gnu mailing list