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 807afdc commit c575e98
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions std/array.d
Expand Up @@ -3018,7 +3018,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 @@ -3053,7 +3053,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 @@ -3402,6 +3402,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

1 comment on commit c575e98

@trikko
Copy link
Contributor

@trikko trikko commented on c575e98 Dec 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.