| 1 |
struct S1 // overall alignment: max(1, 1) = 1 |
| 2 |
{ |
| 3 |
byte[5] bytes; |
| 4 |
struct // overall alignment: max(1, 1) = 1 |
| 5 |
{ |
| 6 |
byte byte1; |
| 7 |
align(1) int int1; |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
static assert(S1.int1.offsetof == 6); |
| 12 |
static assert(S1.alignof == 1); |
| 13 |
static assert(S1.sizeof == 10); |
| 14 |
|
| 15 |
class C2 // overall alignment: max(vtbl.alignof, monitor.alignof, 1, 2) |
| 16 |
{ |
| 17 |
byte[5] bytes; |
| 18 |
struct // overall alignment: max(1, 2) = 2 |
| 19 |
{ |
| 20 |
byte byte1; |
| 21 |
align(2) int int1; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
enum payloadOffset = C2.bytes.offsetof; |
| 26 |
static assert(C2.int1.offsetof == payloadOffset + 8); |
| 27 |
static assert(__traits(classInstanceAlignment, C2) == size_t.sizeof); |
| 28 |
static assert(__traits(classInstanceSize, C2) == payloadOffset + 12); // no tail padding |
| 29 |
|
| 30 |
align(8) struct PaddedStruct |
| 31 |
{ |
| 32 |
bool flag; |
| 33 |
align(2) S1 s1; |
| 34 |
} |
| 35 |
|
| 36 |
static assert(PaddedStruct.s1.offsetof == 2); |
| 37 |
static assert(PaddedStruct.alignof == 8); |
| 38 |
static assert(PaddedStruct.sizeof == 16); |
| 39 |
|
| 40 |
class AlignedPayloadClass |
| 41 |
{ |
| 42 |
align(64) int field; |
| 43 |
} |
| 44 |
|
| 45 |
static assert(AlignedPayloadClass.field.offsetof == 64); // vtbl, monitor, alignment padding |
| 46 |
static assert(__traits(classInstanceAlignment, AlignedPayloadClass) == 64); |
| 47 |
static assert(__traits(classInstanceSize, AlignedPayloadClass) == 68); |
| 48 |
|
| 49 |
align(1) struct UglyStruct |
| 50 |
{ |
| 51 |
bool flag; |
| 52 |
int i; |
| 53 |
ubyte u; |
| 54 |
} |
| 55 |
|
| 56 |
static assert(UglyStruct.i.offsetof == 4); |
| 57 |
static assert(UglyStruct.alignof == 1); |
| 58 |
static assert(UglyStruct.sizeof == 9); |
| 59 |
|
| 60 |
/***************************************************/ |
| 61 |
// https://issues.dlang.org/show_bug.cgi?id=19914 |
| 62 |
// https://issues.dlang.org/show_bug.cgi?id=19915 |
| 63 |
|
| 64 |
class TemplatedClass(T) |
| 65 |
{ |
| 66 |
align T field; |
| 67 |
} |
| 68 |
|
| 69 |
mixin TemplatedClass!(string); |
| 70 |
alias TCint = TemplatedClass!(int); |