mirror of
https://github.com/apple/swift-collections
synced 2026-11-29 05:14:20 +00:00
`TrailingArray.init(header:initializingTrailingElementsWith:)` created the value with just its header, then ran the initializer. If the initializer threw, the half-built value was destroyed, so `deinit` deinitialized all `trailingCount` elements, even though the output span had already deinitialized the ones it had initialized and the rest were never initialized. `withTemporaryValue(header:initializingTrailingElementsWith:body:)` had the same problem through the `defer` in `_withTemporaryValue`. With non-trivial elements (e.g. class references) both crashed. Initialize the trailing elements before creating the `TrailingArray`, and if the initializer throws, only deinitialize the header (and free the heap storage) before rethrowing.
Unit tests
Beware! The contents of this directory are not source stable. They are provided as is, with no compatibility promises across package releases. Future versions of this package can arbitrarily change these files or remove them, without any advance notice. (This can include patch releases.)