Unique!struct bug - Re: unique_ptr | Unique for autoclose handle

Nick Treleaven nick at geany.org
Thu Dec 15 19:31:27 UTC 2022


On Wednesday, 14 December 2022 at 17:41:07 UTC, Ali Çehreli wrote:
> I've never used Unique but I think it has a bug (or a design 
> issue?): Its destructor is the following:
>
>     ~this()
>     {
>         if (_p !is null)
>         {
>             destroy(_p);
>             _p = null;
>         }
>     }
>
> Because _p is a pointer, destroy(_p) will not dereference and 
> destroy what it points to. I think this is a bug with Unique. I 
> think it should do
>
>   destroy(*_p);

Now filed:
https://issues.dlang.org/show_bug.cgi?id=23561

Do you think it's OK to just fix this or do we need to do some 
kind of deprecation?


More information about the Digitalmars-d-learn mailing list