Fix Bugzilla 20872 - std.array.assocArray trusts user-provided 'front… (#9036)

This commit is contained in:
Nick Treleaven 2024-07-31 13:07:23 +01:00 committed by GitHub
parent 4552211174
commit 4641576812
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -663,6 +663,8 @@ if (isInputRange!Values && isInputRange!Keys)
alias ValueElement = ElementType!Values;
static if (hasElaborateDestructor!ValueElement)
ValueElement.init.__xdtor();
aa[key] = values.front;
})))
{
() @trusted {
@ -803,6 +805,20 @@ if (isInputRange!Values && isInputRange!Keys)
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.