Bug 22506 – Accessing immutable AA in @nogc with index results in compilation error

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-11-12T10:48:06Z
Last change time
2024-12-13T19:19:19Z
Assigned to
No Owner
Creator
muhammed.yucel
Moved to GitHub: dmd#20008 →

Comments

Comment #0 by muhammed.yucel — 2021-11-12T10:48:06Z
It will throw the following compilation error Error: indexing an associative array in `@nogc` function `app.myfunc` may cause a GC allocation Here is a code example: immutable int[int] aa; shared static this () { aa[10] = 20; aa[20] = 30; } int myfunc () @nogc { return aa[10]; }
Comment #1 by muhammed.yucel — 2021-12-14T13:38:57Z
Documentation (1) states the "why" for this error but I think it is also wrong. RangeError is statically allocated thus GC shouldn't be a problem but the actual problem is a new key may be allocated when indexing an AA (left side). 1: https://dlang.org/spec/function.html#nogc-functions
Comment #2 by robert.schadek — 2024-12-13T19:19:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20008 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB