aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/compilable/aggr_alignment.d
blob: 0c727e2fec560a81ee1d63b857f4c86a076e765a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
struct S1 // overall alignment: max(1, 1) = 1
{
    byte[5] bytes;
    struct // overall alignment: max(1, 1) = 1
    {
        byte byte1;
        align(1) int int1;
    }
}

static assert(S1.int1.offsetof == 6);
static assert(S1.alignof == 1);
static assert(S1.sizeof == 10);

class C2 // overall alignment: max(vtbl.alignof, monitor.alignof, 1, 2)
{
    byte[5] bytes;
    struct // overall alignment: max(1, 2) = 2
    {
        byte byte1;
        align(2) int int1;
    }
}

enum payloadOffset = C2.bytes.offsetof;
static assert(C2.int1.offsetof == payloadOffset + 8);
static assert(C2.alignof == size_t.sizeof);
static assert(__traits(classInstanceSize, C2) == payloadOffset + 12);

align(8) struct PaddedStruct
{
    bool flag;
    align(2) S1 s1;
}

static assert(PaddedStruct.s1.offsetof == 2);
static assert(PaddedStruct.alignof == 8);
static assert(PaddedStruct.sizeof == 16);

align(1) struct UglyStruct
{
    bool flag;
    int i;
    ubyte u;
}

static assert(UglyStruct.i.offsetof == 4);
static assert(UglyStruct.alignof == 1);
static assert(UglyStruct.sizeof == 9);

/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=19914
// https://issues.dlang.org/show_bug.cgi?id=19915

class TemplatedClass(T)
{
    align T field;
}

mixin TemplatedClass!(string);
alias TCint = TemplatedClass!(int);