[Issue 22185] New: std.array.array() doesn't handle throwing element copying

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 6 13:21:38 UTC 2021


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 at puremagic.com
          Reporter: kinke at 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.

--


More information about the Digitalmars-d-bugs mailing list