Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

fix issue 12330 - array.reserve at compile time too #2532

Merged
merged 1 commit into from Mar 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/object.d
Expand Up @@ -3929,7 +3929,10 @@ private
*/
size_t reserve(T)(ref T[] arr, size_t newcapacity) pure nothrow @trusted
{
return _d_arraysetcapacity(typeid(T[]), newcapacity, cast(void[]*)&arr);
if (__ctfe)
return newcapacity;
else
return _d_arraysetcapacity(typeid(T[]), newcapacity, cast(void[]*)&arr);
}

///
Expand All @@ -3953,6 +3956,18 @@ size_t reserve(T)(ref T[] arr, size_t newcapacity) pure nothrow @trusted
assert(u == a.capacity); //a should not have been extended
}

// https://issues.dlang.org/show_bug.cgi?id=12330, reserve() at CTFE time
@safe unittest
{
int[] foo() {
int[] result;
auto a = result.reserve = 5;
assert(a == 5);
return result;
}
enum r = foo();
}

// Issue 6646: should be possible to use array.reserve from SafeD.
@safe unittest
{
Expand Down