Bug 13661 – static array init does not call destructors
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-27T08:31:00Z
Last change time
2015-02-18T03:40:04Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
shachar
Comments
Comment #0 by shachar — 2014-10-27T08:31:25Z
Please consider the following program:
import std.stdio;
struct S {
int x;
this(this) {
writeln("this(this)");
}
~this() {
writeln("~this()", &this, " ", x);
}
ref auto opAssign(T)(T arg) {
x = arg.x;
writeln("opAssign ", T.stringof, " x=", x);
return this;
}
}
void main() {
S[2] a;
S[2] b;
a[0].x = 12;
a[1].x = 17;
// a = b; // 1
a = a.init; // 2
// a[] = S.init; // 3
writeln("end a=", a[0].x, ", ", a[1].x);
}
At no point is a destructor called for x=12 or x=17. No opAssign is called at all.
Replacing the line marked "2" with either "1" or "3" works just fine.
This is a major blocker for implementing RAII type resource management.