Skip to content

Commit

Permalink
Fix Issue 13300 - pure function 'std.array.Appender!(T[]).Appender.en…
Browse files Browse the repository at this point in the history
…sureAddable' cannot call impure function 'test.T.__fieldPostBlit'
  • Loading branch information
edi33416 committed Dec 18, 2018
1 parent 21afd40 commit a34c2d5
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions std/array.d
Expand Up @@ -3235,7 +3235,7 @@ if (isDynamicArray!A)
* Params:
* newCapacity = the capacity the `Appender` should have
*/
void reserve(size_t newCapacity) @safe pure nothrow
void reserve(size_t newCapacity) @safe nothrow
{
if (_data)
{
Expand Down Expand Up @@ -3270,7 +3270,7 @@ if (isDynamicArray!A)
}

// ensure we can add nelems elements, resizing as necessary
private void ensureAddable(size_t nelems) @trusted pure nothrow
private void ensureAddable(size_t nelems) @trusted nothrow
{
if (!_data)
_data = new Data;
Expand Down Expand Up @@ -3619,6 +3619,41 @@ if (isDynamicArray!A)
app.put(r[]);
}

@safe unittest // issue 13300
{
static test(bool isPurePostblit)()
{
static if (!isPurePostblit)
static int i;

struct Simple
{
@disable this(); // Without this, it works.
static if (!isPurePostblit)
this(this) { i++; }
else
pure this(this) { }

private:
this(int tmp) { }
}

struct Range
{
@property Simple front() { return Simple(0); }
void popFront() { count++; }
@property empty() { return count < 3; }
size_t count;
}

Range r;
auto a = r.array();
}

static assert (__traits(compiles, () pure { test!true(); }));
static assert (!__traits(compiles, () pure { test!false(); }));
}

//Calculates an efficient growth scheme based on the old capacity
//of data, and the minimum requested capacity.
//arg curLen: The current length
Expand Down

0 comments on commit a34c2d5

Please sign in to comment.