digitalmars.D.bugs - [Issue 16508] New: Alignment of class members is not respected.
- via Digitalmars-d-bugs (45/45) Sep 18 2016 https://issues.dlang.org/show_bug.cgi?id=16508
https://issues.dlang.org/show_bug.cgi?id=16508 Issue ID: 16508 Summary: Alignment of class members is not respected. Affects new, scoped and classInstanceAlignment. Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: Marco.Leise gmx.de Illustration: class A { align(8192) ubyte[0x400000] i; } class B : A { import core.simd; void16 giveMeMyAlignment; } void main() { import std.stdio, std.traits; writeln(classInstanceAlignment!B); writeln(cast(void*)new B); } Class B's alignment is 8192 (0x2000), but the program output is: 8 7FEAFA8DF000 This indicates that the alignment directive is silently ignored for `new` and that we have no access to the actual member alignment through compile-time reflection. I had to pick a fantasy alignment here, as otherwise the pointers are always rounded to a value larger than the alignment. We need a way to get at the actual effective class instance alignment at compile time and possibly feed that as a compile-time constant into the `align()` directive for efficient `scoped` implementations. Before anyone asks, the `scope` keyword to place objects on the stack is also affected. But that's a general problem with current dmd, that doesn't support stack alignments > 16 bytes. See: https://issues.dlang.org/show_bug.cgi?id=16098 --
Sep 18 2016