Bug 11204 – Struct is destroyed before constructed
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-09T02:59:00Z
Last change time
2013-10-10T05:14:26Z
Assigned to
nobody
Creator
samukha
Comments
Comment #0 by samukha — 2013-10-09T02:59:12Z
This illustrates what I meant in bug 10186, comment 6:
struct S {
@disable this();
bool cted;
this(int x) {
cted = true;
}
static int destroyedBeforeConstructed;
~this() {
if (!cted)
destroyedBeforeConstructed++;
}
}
class A {
S s;
this() {
s = S(1);
}
}
void main() {
auto a = new A;
assert(S.destroyedBeforeConstructed == 0);
}
Assertion fails because assignment triggers destruction of a struct that has never been constructed.
With this one, object lifetime management remains fatally broken.