diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-06-11 11:08:12 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-06-13 14:08:36 +0100 |
commit | cc38bdf093c44918edff819ae6c73d03c726b341 (patch) | |
tree | a90c3cee080c5d2e7e519b186f95d62102024961 /libstdc++-v3/include/bits/hashtable.h | |
parent | 99a1fe6c12c733fe4923a75a79d09a66ff8abcec (diff) | |
download | gcc-cc38bdf093c44918edff819ae6c73d03c726b341.zip gcc-cc38bdf093c44918edff819ae6c73d03c726b341.tar.gz gcc-cc38bdf093c44918edff819ae6c73d03c726b341.tar.bz2 |
libstdc++: Improve diagnostics for invalid std::hash specializations [PR115420]
When using a key type without a valid std::hash specialization the
unordered containers give confusing diagnostics about the default
constructor being deleted. Add a static_assert that will fail for
disabled std::hash specializations (and for a subset of custom hash
functions).
libstdc++-v3/ChangeLog:
PR libstdc++/115420
* include/bits/hashtable.h (_Hashtable): Add static_assert to
check that hash function is copy constructible.
* testsuite/23_containers/unordered_map/115420.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/bits/hashtable.h')
-rw-r--r-- | libstdc++-v3/include/bits/hashtable.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 983aa90..361da2b 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -210,6 +210,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static_assert(is_same<typename _Alloc::value_type, _Value>{}, "unordered container must have the same value_type as its allocator"); #endif + static_assert(is_copy_constructible<_Hash>::value, + "hash function must be copy constructible"); using __traits_type = _Traits; using __hash_cached = typename __traits_type::__hash_cached; |