“Out” parameters and destructors
Nick Treleaven
nick at geany.org
Mon Mar 17 11:40:59 UTC 2025
On Friday, 14 March 2025 at 07:30:14 UTC, Ogion wrote:
> Functions with `out` parameters simply initialize the parameter
> with `.init`, instead of properly destroying it.
See https://github.com/dlang/dmd/issues/18348.
I think the solution is to always call the destructor before
calling the function. However that was not implemented because it
would break code that uses `S s = void;`, as `s` might not be a
destructible value. The `= void` case could perhaps be supported
if the compiler was smart enough to detect simple cases where `s`
wasn't constructed. In those cases calling the destructor could
be omitted (the spec might need updating to allow that). Given
that all this could still break existing code with non-simple
control flow, it would probably need to be done in the next
edition rather than current edition of the language.
More information about the Digitalmars-d
mailing list