Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bugzilla 24617 - array runtime erroneously copies flags from exis… #16599

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion druntime/src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,33 @@ private BlkInfo __arrayAlloc(size_t arrsize, ref BlkInfo info, const scope TypeI
return BlkInfo();
}

auto bi = GC.qalloc(padded_size, info.attr, tinext);
auto bi = GC.qalloc(padded_size, info.attr | BlkAttr.APPENDABLE, tinext);
__arrayClearPad(bi, arrsize, padsize);
return bi;
}

// https://issues.dlang.org/show_bug.cgi?id=24617
unittest
{
static struct S
{
int[1] val;
}
auto s = new S;
int[] arr = s.val[];
assert(arr.capacity == 0); // starts out without appendability
arr.length = 2;
assert(arr.capacity > 0);

arr = s.val[]; // reset
arr.reserve(100);
assert(arr.capacity > 0);

arr = s.val[]; // reset
arr ~= 10;
assert(arr.capacity > 0);
}

/**
cache for the lookup of the block info
*/
Expand Down
Loading