]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: [_Hashtable] Fix hash code cache usage when stateful hash functor
authorFrançois Dumont <frs.dumont@gmail.com>
Sun, 16 Feb 2025 18:27:49 +0000 (19:27 +0100)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 25 Feb 2025 21:27:14 +0000 (22:27 +0100)
commitbcc8dea6a45b46febfa76df6f5e3e5b13f3b4a58
tree1ea3f5e277df37ea96a375cbfa71d908d07478e6
parentdc9db8007519a3240ebf66262be8baba87a98e20
libstdc++: [_Hashtable] Fix hash code cache usage when stateful hash functor

It is wrong to reuse a cached hash code from another container when this code depends
on the state of the container's Hash functor.

Add checks that Hash functor is stateless before reusing the cached hash code.

libstdc++-v3/ChangeLog:

* include/bits/hashtable_policy.h
(_Hash_code_base::_M_copy_code, _Hash_code_base::_M_store_code): Remove.
* include/bits/hashtable.h (_M_hash_code_ext): New.
(_M_merge_multi(_Hashtable&)): Use latter.
(_M_copy_code): New.
(_M_assign): Use latter.
(_M_bucket_index_ex): New.
(_M_equals): Use latter.
(_M_store_code): New.
(_M_src_hash_code): Remove key_type parameter.
* testsuite/23_containers/unordered_map/modifiers/merge.cc (test10): New
test case.
libstdc++-v3/include/bits/hashtable.h
libstdc++-v3/include/bits/hashtable_policy.h
libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/merge.cc