Thread overview
[Issue 4179] [AA] Deleting items from an associative array iterated over
Apr 17, 2015
Ivan Kazmenko
April 17, 2015
https://issues.dlang.org/show_bug.cgi?id=4179

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com

--- Comment #12 from Andrei Alexandrescu <andrei@erdani.com> ---
We've just had this issue at work, looks like undefined behavior. An associative array with keys deleted during iteration caused crashes without stack trace and without core dump.

The right thing here is to throw an exception if an AA is removed from during an iteration.

--
April 17, 2015
https://issues.dlang.org/show_bug.cgi?id=4179

--- Comment #13 from Ivan Kazmenko <gassa@mail.ru> ---
(In reply to Andrei Alexandrescu from comment #12)
> We've just had this issue at work, looks like undefined behavior. An associative array with keys deleted during iteration caused crashes without stack trace and without core dump.
> 
> The right thing here is to throw an exception if an AA is removed from during an iteration.

Not just removal. Even *adding* (not deleting) elements to associative array can cause reallocation and undefined behavior as well:

https://issues.dlang.org/show_bug.cgi?id=12218

--
April 18, 2015
https://issues.dlang.org/show_bug.cgi?id=4179

--- Comment #14 from Steven Schveighoffer <schveiguy@yahoo.com> ---
We can rewrite the rehash code to rely more on GC destruction, or alter the opApply/range code to be safer. Perhaps this is the right thing to do regardless.

This will probably result in AA's being more likely to cause false pointers.

--