“Out” parameters and destructors

matheus matheus at gmail.com
Tue Mar 18 12:58:10 UTC 2025


On Monday, 17 March 2025 at 11:40:59 UTC, Nick Treleaven wrote:
> 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 ...

Wondering if that's the reason why in C# you need to construct an 
object before passing to an out parameter.

Matheus.


More information about the Digitalmars-d mailing list