[Issue 20285] Struct destructor called multiple times in dynamic arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Oct 8 21:41:49 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20285
kinke <kinke at gmx.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kinke at gmx.net
--- Comment #1 from kinke <kinke at gmx.net> ---
This shows better what's going on:
void main() {
Foo[] array;
array.length = 1;
array[0] = Foo(1);
printf("1st pointer: %p\n", array.ptr);
array.length = 2;
array[1] = Foo(2);
printf("2nd pointer: %p\n", array.ptr);
}
=>
Destroying foo 0
1st pointer: 0x7f9cf69b3000
Destroying foo 0
2nd pointer: 0x7f9cf69b4000
Destroying foo 1
Destroying foo 2
Destroying foo 1
Increasing the length default-constructs instances at the end, which are
destructed when assigning the literals later. These are the first 2 dtor calls.
As a reallocation takes places, the two GC arrays are destructed on program
termination, these are the other 3 dtor calls. Here, the 1st 1-element-array
should probably not be destructed, as it's been moved from (and it hasn't been
reset to T.init either).
--
More information about the Digitalmars-d-bugs
mailing list