cat > bug.d << CODE
int foo(int[int] aa) @safe
{
auto p = 12 in aa;
aa.remove(12);
return *p;
}
CODE
dmd -c bug
----
Here p is a pointer to the value stored in the AA.
Used for anything else but a boolean comparison, `in` is an unsafe operation.
----
cat > bug.d << CODE
int foo(int[] aa) @safe
{
auto p = &aa[12];
aa.length = 10;
return *p;
}
CODE
dmd -c bug
----
Ironically the similar operation on an array isn't treated as unsafe either.
Comment #1 by code — 2015-02-02T11:50:28Z
The array operation really isn't unsafe, because the existing array isn't freed upon reallocating. We can implement similar semantics for the AA without much performance cost, so I'll mark this bug as invalid.