Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/test21665.d

raw
1 /* TEST_OUTPUT:
2 ---
3 fail_compilation/test21665.d(18): Error: `void` initializing a struct with an invariant is not allowed in a `@safe` function
4 fail_compilation/test21665.d(30): Error: accessing overlapped field `U.s` with a structs invariant is not allowed in a `@safe` function
5 ---
6 */
7
8 // https://issues.dlang.org/show_bug.cgi?id=21665
9
10 struct ShortString {
11 private ubyte length;
12 private char[15] data;
13
14 invariant { assert(length <= data.length); }
15 }
16
17 @safe void test1() {
18 ShortString s = void;
19 }
20
21 union U
22 {
23 int n;
24 ShortString s;
25 }
26
27 @safe void test2()
28 {
29 U u;
30 u.s.length = 3;
31 }