mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
39 lines
722 B
D
39 lines
722 B
D
/*
|
|
TEST_OUTPUT:
|
|
---
|
|
fail_compilation/diag11756.d(15): Error: cannot read uninitialized variable `cnt` in CTFE
|
|
fail_compilation/diag11756.d(34): called from here: `foo.ptr2.opAssign(Ptr(& n))`
|
|
fail_compilation/diag11756.d(39): called from here: `test()`
|
|
fail_compilation/diag11756.d(39): while evaluating: `static assert(test())`
|
|
---
|
|
*/
|
|
|
|
struct Ptr
|
|
{
|
|
void opAssign(Ptr other)
|
|
{
|
|
(*cnt)--; // error
|
|
cnt = other.cnt;
|
|
(*cnt)++;
|
|
}
|
|
size_t *cnt;
|
|
}
|
|
|
|
union Foo
|
|
{
|
|
size_t *ptr1;
|
|
Ptr ptr2;
|
|
}
|
|
|
|
bool test()
|
|
{
|
|
Foo foo;
|
|
size_t cnt = 1;
|
|
foo.ptr1 = &cnt;
|
|
size_t n;
|
|
foo.ptr2 = Ptr(&n);
|
|
assert(cnt == 0);
|
|
|
|
return true;
|
|
}
|
|
static assert(test());
|