www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21983] New: dup leaves a partially constructed array if

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

          Issue ID: 21983
           Summary: dup leaves a partially constructed array if
                    postblit/copy ctor throws
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

dup calls user-defined postblits/copy constructor when creating a new array.
But it doesn't destroy the partially constructed array when the postblit/copy
constructors throws an exception. The GC will destroy the array (including
uninitialized elements!) at an undefined time. 

dup should destroy the initialized portion of the array and prevent the
destruction of uninitialized objects (e.g. by manually freeing the memory).

--
May 28 2021