www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23561] New: std.typecons.Unique!struct does not destroy

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

          Issue ID: 23561
           Summary: std.typecons.Unique!struct does not destroy struct
                    instance
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: nick geany.org

void main()
{
    import std.typecons;

    int i;
    struct S
    {
        ~this() { i++; }
    }
    {
        Unique!S u = new S;
    }
    assert(i == 1); // fails
}

Unique.~this calls destroy on the S*, not the struct instance:

        if (_p !is null)
        {
            destroy(_p);
            _p = null;
        }

--
Dec 15 2022