[Issue 15662] Cannot move struct with defined opAssign due to @disabled post-blit
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Feb 9 05:33:39 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15662
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
This is expected behavior. Appending element to array would cause reallocation
if there's no array.capacity. It's not related whether the appended element is
unique.
D's built-in array is a view of original memory. The viewed memory is not owned
by the array slice, so we cannot destroy the original elements freely.
Therefore, when the reallocation happens, the original elements will be copied
to a newly allocated memory (its size is enough larger than the original
array.length), then the old elements are copied into it _by using postblit_.
Finally the unique element will be moved into the allocated room.
During compilation, compiler cannot know whether the appending won't cause
reallocation, so it's conservatively rejected because of @disable-d postblit.
--
More information about the Digitalmars-d-bugs
mailing list