void main () @safe { int[string] aa; foreach (val; aa.byKeyValue) ++aa[val.key]; } /d399/f220.d(4): Error: @safe function 'D main' cannot call @system function 'object.byKeyValue!(int[string], string, int).byKeyValue' /d399/f220.d(4): Error: @safe function 'D main' cannot call @system function 'object.byKeyValue!(int[string], string, int).byKeyValue.Result.empty' /d399/f220.d(4): Error: @safe function 'D main' cannot call @system function 'object.byKeyValue!(int[string], string, int).byKeyValue.Result.popFront' /d399/f220.d(5): Error: @safe function 'D main' cannot call @system function 'object.byKeyValue!(int[string], string, int).byKeyValue.Result.front.Pair.key'
Hmph. This is caused by the last line in object.byKeyValue()(): ---- /usr/src/d/druntime/import/object.d(2071): Error: cast from int[string] to void* not allowed in safe code test.d(4): Error: template instance object.byKeyValue!(int[string], string, int) error instantiating ---- Could this be a regression? I vaguely recall casting to void* used to be allowed, you just can't dereference it unless you're in @trusted land.
Bah. Regardless of whether the void* cast is allowed or not, _aaRange() is @system so it's still a no-go.
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/51003a398b77eca1b01138412f2e363c38172878 fix issue 17108 Associative array byKeyValue is unsafe https://github.com/dlang/druntime/commit/3bf2559ce08d449d8d486a4df3f74343f5b70b33 Merge pull request #1944 from somzzz/make_foreach_byKeyValue_safe fix issue 17108 Associative array byKeyValue is unsafe
Commits pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/51003a398b77eca1b01138412f2e363c38172878 fix issue 17108 Associative array byKeyValue is unsafe https://github.com/dlang/druntime/commit/3bf2559ce08d449d8d486a4df3f74343f5b70b33 Merge pull request #1944 from somzzz/make_foreach_byKeyValue_safe