summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/test21665.d
blob: a3a348dd0338e921c72f4b634b1c4ec3801209b3 (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
/* TEST_OUTPUT:
---
fail_compilation/test21665.d(18): Error: variable `test21665.test1.s` `void` initializers for structs with invariants are not allowed in safe functions
fail_compilation/test21665.d(30): Error: field `U.s` cannot access structs with invariants in `@safe` code that overlap other fields
---
*/

// https://issues.dlang.org/show_bug.cgi?id=21665

struct ShortString {
    private ubyte length;
    private char[15] data;

    invariant { assert(length <= data.length); }
}

@safe void test1() {
    ShortString s = void;
}

union U
{
    int n;
    ShortString s;
}

@safe void test2()
{
    U u;
    u.s.length = 3;
}