mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
Fix Bugzilla 20872 - std.array.assocArray trusts user-provided 'front… (#9036)
This commit is contained in:
parent
4552211174
commit
4641576812
1 changed files with 16 additions and 0 deletions
16
std/array.d
16
std/array.d
|
@ -663,6 +663,8 @@ if (isInputRange!Values && isInputRange!Keys)
|
||||||
alias ValueElement = ElementType!Values;
|
alias ValueElement = ElementType!Values;
|
||||||
static if (hasElaborateDestructor!ValueElement)
|
static if (hasElaborateDestructor!ValueElement)
|
||||||
ValueElement.init.__xdtor();
|
ValueElement.init.__xdtor();
|
||||||
|
|
||||||
|
aa[key] = values.front;
|
||||||
})))
|
})))
|
||||||
{
|
{
|
||||||
() @trusted {
|
() @trusted {
|
||||||
|
@ -803,6 +805,20 @@ if (isInputRange!Values && isInputRange!Keys)
|
||||||
assert(assocArray(1.iota, [UnsafeElement()]) == [0: UnsafeElement()]);
|
assert(assocArray(1.iota, [UnsafeElement()]) == [0: UnsafeElement()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
struct ValueRange
|
||||||
|
{
|
||||||
|
string front() const @system;
|
||||||
|
@safe:
|
||||||
|
void popFront() {}
|
||||||
|
bool empty() const { return false; }
|
||||||
|
}
|
||||||
|
int[] keys;
|
||||||
|
ValueRange values;
|
||||||
|
static assert(!__traits(compiles, assocArray(keys, values)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Construct a range iterating over an associative array by key/value tuples.
|
Construct a range iterating over an associative array by key/value tuples.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue