import std.container; void main() { Array!int a; // empty Array a.length = 10; // now payload is allocated, length is set to 10, but capacity is still 0! // try to append a value a ~= 1; // runtime error (assertion: capacity < length !) } Fix is trivial, Array.Payload.length setter must update _capacity field when it reallocates data.
That's not fixed yet !?
I think the bug you reported is not valid. However, there is a bug when using length to shorten the array: import std.container; void main() { Array!int a; // empty Array a.length = 10; // a contains 10 default ints a.length = 9; // Remove one, should have capacity > 0 assert(a.capacity > 0); }
Why do you think it's not valid? It does throw runtime error and capacity is wrong after setting the length. http://dpaste.dzfl.pl/b10858af2a56
Ah, I misinterpreted the meaning of the capacity (unused capacity vs total capacity.) Perhaps the title should be "std.container.array capacity not updated when changing length" or something like that since it's not specific to increasing length.
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619 Fix issue 13619 - array capacity not updated when changing length merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619
Commits pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619