Skip to content

Commit

Permalink
Fix Bugzilla 24617 - array runtime erroneously copies flags from exis…
Browse files Browse the repository at this point in the history
…ting block
  • Loading branch information
ntrel committed Jun 19, 2024
1 parent c6058f9 commit 11f8a43
Showing 1 changed file with 23 additions and 1 deletion.
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

0 comments on commit 11f8a43

Please sign in to comment.