digitalmars.D - =?UTF-8?B?4oCcT3V04oCd?= parameters and destructors
- Ogion (40/40) Mar 14 Functions with `out` parameters simply initialize the parameter
Functions with `out` parameters simply initialize the parameter with `.init`, instead of properly destroying it. ```D 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.
Mar 14