Debian Codegraph @

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

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/diag11756.d(15): Error: cannot read uninitialized variable `cnt` in CTFE
5 fail_compilation/diag11756.d(34): called from here: `foo.ptr2.opAssign(Ptr(& n))`
6 fail_compilation/diag11756.d(39): called from here: `test()`
7 fail_compilation/diag11756.d(39): while evaluating: `static assert(test())`
8 ---
9 */
10
11 struct Ptr
12 {
13 void opAssign(Ptr other)
14 {
15 (*cnt)--; // error
16 cnt = other.cnt;
17 (*cnt)++;
18 }
19 size_t *cnt;
20 }
21
22 union Foo
23 {
24 size_t *ptr1;
25 Ptr ptr2;
26 }
27
28 bool test()
29 {
30 Foo foo;
31 size_t cnt = 1;
32 foo.ptr1 = &cnt;
33 size_t n;
34 foo.ptr2 = Ptr(&n);
35 assert(cnt == 0);
36
37 return true;
38 }
39 static assert(test());