www.digitalmars.com         C & C++   DMDScript  

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


          Issue ID: 22337
           Summary: `std.container.Array` object leak (on failed
           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


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:

Sep 27 2021