Thread overview
[Issue 21983] dup leaves a partially constructed array if postblit/copy ctor throws
May 28, 2021
Dlang Bot
Nov 02, 2021
RazvanN
May 28, 2021
https://issues.dlang.org/show_bug.cgi?id=21983

--- Comment #1 from moonlightsentinel@disroot.org ---
Test case (run with current master):

import core.stdc.stdio : puts, printf;

struct S {
    private int id;

    this(this)
    {
        if (id == 2)
            throw new Exception("");
    }

    ~this()
    {
        printf("Destroying %d at %p\n", id, &this);
    }
}

void main()
{
    try
    {
        S[3] arr = [ S(1), S(2), S(3) ];
        arr.dup();
    }
    catch (Exception e) {}

    puts("Done");
}

====

Destroying 3 at 0x7fffcd3f3888
Destroying 2 at 0x7fffcd3f3884
Destroying 1 at 0x7fffcd3f3880
Done
Destroying -968732576 at 0x7fea0ce90008
Destroying 2 at 0x7fea0ce90004
Destroying 1 at 0x7fea0ce90000

--
May 28, 2021
https://issues.dlang.org/show_bug.cgi?id=21983

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

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

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@MoonlightSentinel created dlang/druntime pull request #3483 "Fix 21983 - Destroy partially dup'ed array if postblit/copy ctor throws" fixing this issue:

- Fix 21983 - Destroy partially dup'ed array if postblit/copy ctor throws

  This ensures deterministic behaviour in case of an exception and
  avoids dtor calls on uninitialized elements.

https://github.com/dlang/druntime/pull/3483

--
November 02, 2021
https://issues.dlang.org/show_bug.cgi?id=21983

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |FIXED

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
Fixed by https://github.com/dlang/druntime/pull/3483

--