arrays of struct - critical bug?
Jack Applegame
japplegame at gmail.com
Sun May 19 02:57:18 PDT 2013
Calling constructors/destructors/postblits for structs in array
is totally unpredictable.
dmd 2.062 - http://dpaste.1azy.net/445359ad
gdc 2.060 - http://dpaste.1azy.net/7d0bf021
ldc 2.060 - http://dpaste.1azy.net/74034586
Code:
import std.stdio;
struct A {
this(int a) { m = a; writefln("constructor %s", m); }
this(this) { writefln("postblit %s", m); }
ref A opAssign(ref A other) { writefln("assign %s", m); return
this; }
~this() { writefln("destructor %s", m); }
int m;
}
void main() {
writeln("-- begin --");
A[] arr1= [A(1), A(2)];
writeln("-----------");
A[2] arr2 = [A(3), A(4)];
writeln("--- end ---");
}
I believe that each constructor/postblit must correspond to the
destructor and vice versa.
But we see double/missing destructors and (in case of gdc) even
destruction of unknown things.
This is breaks in particular RefCounted concept:
http://dpaste.1azy.net/7241b101
More information about the Digitalmars-d-learn
mailing list