Skip to content

Commit

Permalink
Merge pull request #5028 from somzzz/issue_16542
Browse files Browse the repository at this point in the history
fix issue 16542 -  makeArray not usable with const initializer
  • Loading branch information
andralex authored Oct 30, 2017
2 parents b147252 + cd66c0c commit 2e92719
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions std/experimental/allocator/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,7 @@ private enum hasPureDtor(T) = !hasElaborateDestructor!T ||
private enum canSafelyDeallocPostRewind(T) = hasPurePostblit!T && hasPureDtor!T;

/// Ditto
T[] makeArray(T, Allocator)(auto ref Allocator alloc, size_t length,
auto ref T init)
T[] makeArray(T, Allocator)(auto ref Allocator alloc, size_t length, T init)
{
if (!length) return null;
auto m = alloc.allocate(T.sizeof * length);
Expand Down Expand Up @@ -1094,6 +1093,18 @@ T[] makeArray(T, Allocator)(auto ref Allocator alloc, size_t length,
test!(immutable int)();
}

@system unittest
{
void test(T)(in T initialValue)
{
auto t = theAllocator.makeArray!T(100, initialValue);
//auto t = theAllocator.makeArray(100, initialValue); // works well with the old code
}

const int init = 3;
test(init);
}

@system unittest
{
void test(A)(auto ref A alloc)
Expand Down

0 comments on commit 2e92719

Please sign in to comment.