Skip to content

Commit 18c4248

Browse files
authored
Merge pull request #6832 from FeepingCreature/fix/Issue-19572
Fix issue 19572: Prevent Appender from implicitly calling struct constructors to cast away const. merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 1e43568 + 7876c1d commit 18c4248

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

std/array.d

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,7 @@ if (isDynamicArray!A)
33393339
private template canPutItem(U)
33403340
{
33413341
enum bool canPutItem =
3342-
isImplicitlyConvertible!(U, T) ||
3342+
isImplicitlyConvertible!(Unqual!U, Unqual!T) ||
33433343
isSomeChar!T && isSomeChar!U;
33443344
}
33453345
private template canPutConstRange(Range)
@@ -3384,7 +3384,7 @@ if (isDynamicArray!A)
33843384
immutable len = _data.arr.length;
33853385

33863386
auto bigData = (() @trusted => _data.arr.ptr[0 .. len + 1])();
3387-
emplaceRef!(Unqual!T)(bigData[len], cast(Unqual!T) item);
3387+
emplaceRef!(Unqual!T)(bigData[len], cast() item);
33883388
//We do this at the end, in case of exceptions
33893389
_data.arr = bigData;
33903390
}
@@ -3657,6 +3657,26 @@ if (isDynamicArray!A)
36573657
static assert(!__traits(compiles, () pure { test!false(); }));
36583658
}
36593659

3660+
@system unittest // issue 19572
3661+
{
3662+
static struct Struct
3663+
{
3664+
int value;
3665+
3666+
int fun() const { return 23; }
3667+
3668+
alias fun this;
3669+
}
3670+
3671+
Appender!(Struct[]) appender;
3672+
3673+
appender.put(const(Struct)(42));
3674+
3675+
auto result = appender.data[0];
3676+
3677+
assert(result.value != 23);
3678+
}
3679+
36603680
//Calculates an efficient growth scheme based on the old capacity
36613681
//of data, and the minimum requested capacity.
36623682
//arg curLen: The current length

0 commit comments

Comments
 (0)