Idomatic way to guarantee to run destructor?

Olivier Pisano olivier.pisano at laposte.net
Mon May 4 09:47:49 UTC 2020


On Monday, 4 May 2020 at 09:20:06 UTC, Ali Çehreli wrote:
> On 4/30/20 10:04 AM, Ben Jones wrote:> On Thursday, 30 April 
> 2020 at 16:55:36 UTC, Robert M. Münch wrote:
>
> > I think you want to use scope rather than auto which will put
> the class
> > on the stack and call its destructor:
> > https://dlang.org/spec/attribute.html#scope
>
> That is correct about calling the destructor but the object 
> would still be allocated with 'new', hence be on the heap. 
> There is also library feature 'scoped', which places the object 
> on the stack:
>
>   https://dlang.org/phobos/std_typecons.html#scoped
>
> Ali

https://godbolt.org/z/SEVsp5

My ASM skills are pretty limited, but it seems to me that the 
call to _d_allocclass is omitted when using scope. At least with 
LDC and GDC.

Am I missing something ?


More information about the Digitalmars-d-learn mailing list