d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / diag11756.d
blob3a0724792c6553c55127436ce5b057e7d3c2d62f
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 */
11 struct Ptr
13 void opAssign(Ptr other)
15 (*cnt)--; // error
16 cnt = other.cnt;
17 (*cnt)++;
19 size_t *cnt;
22 union Foo
24 size_t *ptr1;
25 Ptr ptr2;
28 bool test()
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);
37 return true;
39 static assert(test());