www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22185] New: std.array.array() doesn't handle throwing element

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

          Issue ID: 22185
           Summary: std.array.array() doesn't handle throwing element
                    copying
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

If the source range has a length, it allocates an uninitialized array and fills
it with copies. If a copy throws (throwing postblit/copy constructor), that
element and the following ones are in no well-defined state, and if the element
type has a destructor, the GC will eventually try to destruct garbage elements.

Relevant code:
https://github.com/dlang/phobos/blob/ccecbda25f1114bca2782c971e7d47cf65abd825/std/array.d#L126-L134

It should probably use new `core.lifetime.copyEmplace()` too.

Analogous to druntime issue https://issues.dlang.org/show_bug.cgi?id=21983.

--
Aug 06 2021