Comment #0 by bearophile_hugs — 2014-07-07T02:19:35Z
void foo(int[int] aa) @nogc {
auto y = aa[0];
}
void main() {}
Gives with dmd 2.066beta1:
test.d(2,16): Error: indexing an associative array in @nogc function foo may cause GC allocation
AA.rehash could cause memory allocations, but looking for a key in an associative could be regarded as @nogc.
Comment #1 by dlang-bugzilla — 2017-07-02T18:02:45Z
If the index is not in the AA, then a RangeError is thrown. The error is currently allocated on the GC heap.
The "in" operator is @nogc, though.
Comment #2 by b2.temp — 2019-06-30T07:46:27Z
I thought this could be closed because of -dip1008 but that doesn't work either.
I suppose it's because druntime is not compiled with -dip1008.
Anyway this issue must be closed because druntime gives the security of range checking and this comes to the price of allocating exception. This is not a special little case that can be fixed with a workaround.
Comment #3 by contact — 2022-10-22T10:57:26Z
(In reply to Vladimir Panteleev from comment #1)
> If the index is not in the AA, then a RangeError is thrown. The error is
> currently allocated on the GC heap.
>
> The "in" operator is @nogc, though.
This is not true. I think it never was, but, at least, right now, the RangeError is statically allocated on thread-local storage. And this is a bounds check, the same as normal array indexing.
Comment #4 by dlang-bot — 2022-10-22T10:59:38Z
@ljmf00 created dlang/dmd pull request #14585 "fix(nogc): associative array indexing may only cause GC allocation no assignment" fixing this issue:
- fix(nogc): associative array indexing may only cause GC allocation no assignment
Fix issue 13060.
Signed-off-by: Luís Ferreira <[email protected]>
https://github.com/dlang/dmd/pull/14585
Comment #5 by dlang-bot — 2022-10-24T13:34:56Z
dlang/dmd pull request #14585 "fix(nogc): associative array indexing may only cause GC allocation on assignment" was merged into master:
- 6c0eeaad82b6aa6e6e5fbb6c0b4862396127fb40 by Luís Ferreira:
fix(nogc): associative array indexing may only cause GC allocation no assignment
Fix issue 13060.
Signed-off-by: Luís Ferreira <[email protected]>
https://github.com/dlang/dmd/pull/14585