Re: “Out” parameters and destructors

Ali Çehreli acehreli at yahoo.com
Fri Mar 14 16:54:10 UTC 2025


On 3/14/25 12:30 AM, Ogion wrote:
 > Functions with `out` parameters simply initialize the parameter with
 > `.init`, instead of properly destroying it.

It took me a while to understand the point. In other words:

     auto s = S(43);
     foo(s);

The destructor of 'S(43)' is never called. Although understandably 
undesirable, this is according to spec:

   https://dlang.org/spec/function.html#ref-params

"An out parameter [...] is initialized with x.init upon function 
invocation."

Perhaps the compiler should not allow using constructed objects as 'out' 
parameter arguments.

Ali



More information about the Digitalmars-d mailing list