From 6ff956e3c2b0369d8312e9fb3f9fab0b67720b07 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 21 Jan 2014 19:38:35 +0000 Subject: [PATCH] re PR libstdc++/56267 (unordered containers require Assignable hash function) PR libstdc++/56267 * include/bits/hashtable.h (__cache_default): Do not depend on whether the hash function is DefaultConstructible or CopyAssignable. (_Hashtable): Adjust static assertions. * doc/xml/manual/containers.xml (containers.unordered.cache): Update. * testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust dg-error line number. * testsuite/23_containers/unordered_set/ not_default_constructible_hash_neg.cc: Remove. From-SVN: r206904 --- libstdc++-v3/ChangeLog | 12 +++++ libstdc++-v3/doc/xml/manual/containers.xml | 21 ++------ libstdc++-v3/include/bits/hashtable.h | 20 -------- .../unordered_set/instantiation_neg.cc | 2 +- .../not_default_constructible_hash_neg.cc | 51 ------------------- 5 files changed, 16 insertions(+), 90 deletions(-) delete mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c25e0f31b5c..879efe887a1 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2014-01-21 Jonathan Wakely + + PR libstdc++/56267 + * include/bits/hashtable.h (__cache_default): Do not depend on + whether the hash function is DefaultConstructible or CopyAssignable. + (_Hashtable): Adjust static assertions. + * doc/xml/manual/containers.xml (containers.unordered.cache): Update. + * testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust + dg-error line number. + * testsuite/23_containers/unordered_set/ + not_default_constructible_hash_neg.cc: Remove. + 2014-01-20 François Dumont * scripts/create_testsuite_files: Add testsuite/experimental in diff --git a/libstdc++-v3/doc/xml/manual/containers.xml b/libstdc++-v3/doc/xml/manual/containers.xml index 9791953b78d..653033da4d5 100644 --- a/libstdc++-v3/doc/xml/manual/containers.xml +++ b/libstdc++-v3/doc/xml/manual/containers.xml @@ -420,7 +420,7 @@ the hash code every time it's needed can improve performance, but the additional memory overhead can also reduce performance, so whether an unordered associative container caches the hash code or not depends on - a number of factors. The caching policy for GCC 4.8 is described below. + the properties described below. The C++ standard requires that erase and swap @@ -432,23 +432,8 @@ or throw(). - Secondly, libstdc++ also needs the hash code in the implementation of - local_iterator and const_local_iterator in - order to know when the iterator has reached the end of the bucket. - This means that the local iterator types will embed a copy of the hash - function when possible. - Because the local iterator types must be DefaultConstructible and - CopyAssignable, if the hash function type does not model those concepts - then it cannot be embedded and so the hash code must be cached. - Note that a hash function might not be safe to use when - default-constructed (e.g if it a function pointer) so a hash - function that is contained in a local iterator won't be used until - the iterator is valid, so the hash function has been copied from a - correctly-initialized object. - - - If the hash function is non-throwing, DefaultConstructible and - CopyAssignable then libstdc++ doesn't need to cache the hash code for + If the hash function is non-throwing then libstdc++ doesn't need to + cache the hash code for correctness, but might still do so for performance if computing a hash code is an expensive operation, as it may be for arbitrarily long strings. diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index e427c7f2383..4297c5fc750 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -42,10 +42,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __cache_default = __not_<__and_, - // Mandatory to make local_iterator default - // constructible and assignable. - is_default_constructible<_Hash>, - is_copy_assignable<_Hash>, // Mandatory to have erase not throwing. __detail::__is_noexcept_hash<_Tp, _Hash>>>; @@ -282,22 +278,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "Functor used to map hash code to bucket index" " must be 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 - // default constructible. - static_assert(__if_hash_not_cached< - is_default_constructible<__hash_code_base_access>>::value, - "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"); - template. -// { dg-error "with noexcept" "" { target *-*-* } 270 } +// { dg-error "with noexcept" "" { target *-*-* } 266 } #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 deleted file mode 100644 index 2365556767c..00000000000 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc +++ /dev/null @@ -1,51 +0,0 @@ -// { dg-do compile } -// { dg-options "-std=c++11" } -// { dg-require-normal-mode "" } - -// Copyright (C) 2013-2014 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -// { dg-error "default constructible" "" { target *-*-* } 288 } - -#include - -namespace -{ - struct hash - { - hash(std::size_t seed) - : _M_seed(seed) - { } - - std::size_t operator() (int val) const noexcept - { return val ^ _M_seed; } - - private: - std::size_t _M_seed; - }; -} - -void -test01() -{ - using traits = std::__detail::_Hashtable_traits; - using hashtable = std::__uset_hashtable, - std::allocator, traits>; - - hashtable ht(10, hash(1)); -}