Fix realloc for non-trivial types.
Fix realloc for non-trivial types.
If a non-trivial type RequiresInitialization
, then we unfortunately
can't simply rely on realloc
to move the memory to a new buffer.
If the data type contains self-referencing pointers (as does
AnnoyingScalar
in tests), then those pointers become invalid.
Instead, we need to allocate a new buffer and copy-construct (or
move-construct) existing elements.
This fixes some failing tests in sparse_block
, which tickled the
bug.