Thread overview
[Issue 23561] std.typecons.Unique!struct does not destroy struct instance
Dec 16, 2022
Vital
Dec 16, 2022
Vital
Dec 16, 2022
Dlang Bot
Dec 17, 2022
Iain Buclaw
Dec 24, 2022
Dlang Bot
December 16, 2022
https://issues.dlang.org/show_bug.cgi?id=23561

Vital <vital.fadeev@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vital.fadeev@gmail.com
                 OS|Linux                       |Windows

--- Comment #1 from Vital <vital.fadeev@gmail.com> ---
import std.stdio;

static int i;

struct S
{
    ~this() {
        i++;
        writeln("DTOR: i == ", i );
    }
}


void main()
{
    {
        auto u = new S;
        u.destroy();
        // (*u).destroy(); // works fine!
    }

    import core.memory;
    GC.collect();

    writeln("EXIT: i == ", i ); // 0, but except 1

    assert(i == 1); // fails
}

// Output:
//   EXIT: i == 0
//   DTOR: i == 1
//
// core.exception.AssertError@source\app.d(24): Assertion failure



Confirm. Also failed.

FAIL: Destructor S, possible not called.
WANTED: Wanted to call S.~this().
PURPOSE: smart-pointer. std.typecons.Unique!S for auto close handle.
DMD: DMD32 D Compiler v2.101.0-dirty, Windows 10, x64
DMD: LDC 1.30, Windows 10, x64

--
December 16, 2022
https://issues.dlang.org/show_bug.cgi?id=23561

--- Comment #2 from Vital <vital.fadeev@gmail.com> ---
But works when S is class:

class S
{
    ~this() {
        i++;
        writeln("DTOR: i == ", i );
    }
}

--
December 16, 2022
https://issues.dlang.org/show_bug.cgi?id=23561

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@ntrel created dlang/phobos pull request #8651 "Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct …" fixing this issue:

- Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct instance

https://github.com/dlang/phobos/pull/8651

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23561

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23561

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/phobos pull request #8651 "Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct …" was merged into master:

- 8df49f52fd8a36a2247e15cc47e8b165e0dd485f by Nick Treleaven:
  Fix Issue 23561 - std.typecons.Unique!struct does not destroy struct instance

https://github.com/dlang/phobos/pull/8651

--