www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22337] New: `std.container.Array` object leak (on failed

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

          Issue ID: 22337
           Summary: `std.container.Array` object leak (on failed
                    construction)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: adder.thief+1 gmail.com

`std.container.Array`:

The constructor taking variadic arguments (which is used in e.g.: `auto a =
Array (S (0), S (1), S (2), S(3));`:

If `emplace`-ing one of the given elements in the newly-created `Array` fails
(by `throw`-ing an `Exception`), the construction of the `Array` fails (by
propagating the `Exception`) (and this is correct), but the already-`emplace`-d
elements are not destroyed (and this is incorrect).

Details and `unittest` and proposed fix:
https://github.com/dlang/phobos/pull/8162.

--
Sep 27 2021