From dfed5434f3946d39cef0d6965891a927f8b388d2 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 11 Feb 2013 00:19:29 +0000 Subject: [PATCH] re PR libstdc++/56267 (unordered containers require Assignable hash function) PR libstdc++/56267 * include/bits/hashtable.h (__cache_default): Check if hash function is copy assignable. * testsuite/23_containers/unordered_set/56267.cc: New. * testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust dg-error line number. * testsuite/23_containers/unordered_set/ not_default_constructible_hash_neg.cc: Likewise. From-SVN: r195936 --- libstdc++-v3/ChangeLog | 9 +++++ libstdc++-v3/include/bits/hashtable.h | 11 +++++- .../23_containers/unordered_set/56267.cc | 35 +++++++++++++++++++ .../unordered_set/instantiation_neg.cc | 2 +- .../not_default_constructible_hash_neg.cc | 2 +- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/56267.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 775ad99e213..522c8851a00 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2013-02-10 Jonathan Wakely + PR libstdc++/56267 + * include/bits/hashtable.h (__cache_default): Check if hash function + is copy assignable. + * testsuite/23_containers/unordered_set/56267.cc: New. + * testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust + dg-error line number. + * testsuite/23_containers/unordered_set/ + not_default_constructible_hash_neg.cc: Likewise. + PR libstdc++/56278 * include/bits/hashtable_policy.h (_Hash_code_base): Make default constructor public. diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 6515b71eef9..b82cda3fa21 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -43,8 +43,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = __not_<__and_, // Mandatory to make local_iterator default - // constructible. + // constructible and assignable. is_default_constructible<_Hash>, + is_copy_assignable<_Hash>, // Mandatory to have erase not throwing. __detail::__is_noexcept_hash<_Tp, _Hash>>>; @@ -269,6 +270,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "Cache the hash code or make functors involved in hash code" " and bucket index computation default constructible"); + // When hash codes are not cached local iterator inherits from + // __hash_code_base above to compute node bucket index so it has to be + // assignable. + static_assert(__if_hash_not_cached< + is_copy_assignable<__hash_code_base>>::value, + "Cache the hash code or make functors involved in hash code" + " and bucket index computation copy assignable"); + public: template. + +// libstdc++/56267 + +#include + +struct hash : std::hash +{ + hash& operator=(const hash&) = delete; +}; + +int main() +{ + std::unordered_set s{ 0, 1, 2 }; + auto i = s.begin(0); + i = i; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc index 827691f2ce0..6712d626231 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "with noexcept" "" { target *-*-* } 251 } +// { dg-error "with noexcept" "" { target *-*-* } 252 } #include diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc index bd62a0808c7..53a25bc65b8 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "default constructible" "" { target *-*-* } 267 } +// { dg-error "default constructible" "" { target *-*-* } 268 } #include -- 2.30.2