Functions with out
parameters simply initialize the parameter with .init
, instead of properly destroying it.
import std.stdio;
int count;
struct S {
bool initialized;
this(int) {
writeln("S()");
initialized = true;
count++;
}
~this() {
if (initialized) {
writeln("~S()");
count--;
}
}
}
void foo(out S s) {
s = S(42);
}
void bar() {
S s;
foo(s);
foo(s);
}
void main() {
bar();
writeln(count);
}
Output:
S()
S()
~S()
1
Looks like a serious oversight.