Bug 17108 – Associative array byKeyValue is unsafe

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-01-19T14:07:09Z
Last change time
2017-12-18T22:54:34Z
Keywords
safe
Assigned to
Lucia Cojocaru
Creator
Jack Stouffer
See also
https://issues.dlang.org/show_bug.cgi?id=17507

Comments

Comment #0 by jack — 2017-01-19T14:07:09Z
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'
Comment #1 by hsteoh — 2017-03-09T00:20:55Z
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.
Comment #2 by hsteoh — 2017-03-09T00:25:58Z
Bah. Regardless of whether the void* cast is allowed or not, _aaRange() is @system so it's still a no-go.
Comment #3 by github-bugzilla — 2017-11-06T14:15:13Z
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
Comment #4 by github-bugzilla — 2017-12-18T22:54:34Z
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