[Bug libstdc++/67922] [DR 2550] std::unordered_map::clear should take time linear in the number of elements

tkaminsk at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 19 13:57:07 GMT 2026


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67922

Tomasz Kamiński <tkaminsk at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tkaminsk at gcc dot gnu.org

--- Comment #10 from Tomasz Kamiński <tkaminsk at gcc dot gnu.org> ---
> We could look at making _M_deallocate_nodes check if each node is the last in a bucket, and if so, set the bucket to nullptr

As we are only thread modifying container we could unconditionally set
_M_bucket to nullptr, without checking if we are last node. The iteration does
not depends on bucket, only on _M_nxt pointer.


More information about the Gcc-bugs mailing list