diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2018-09-21 20:39:07 +0000 |
---|---|---|
committer | François Dumont <fdumont@gcc.gnu.org> | 2018-09-21 20:39:07 +0000 |
commit | 9b297949628f17f7620032e035154225b2d238aa (patch) | |
tree | a80a9ec9f84e791aad92b4826b5357835dad7a42 /libstdc++-v3 | |
parent | 35b66f30438dfac74e4bdcfc7904e9b9cf72b823 (diff) | |
download | gcc-9b297949628f17f7620032e035154225b2d238aa.zip gcc-9b297949628f17f7620032e035154225b2d238aa.tar.gz gcc-9b297949628f17f7620032e035154225b2d238aa.tar.bz2 |
re PR libstdc++/87135 ([C++17] unordered containers violate iterator validity requirements)
2018-09-21 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/87135
* src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt):
Use __builtin_floor to compute _M_next_resize.
* testsuite/23_containers/unordered_set/hash_policy/71181.cc: Adapt.
* testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc:
Adapt.
From-SVN: r264494
Diffstat (limited to 'libstdc++-v3')
4 files changed, 19 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 161ea11..e64f11c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2018-09-21 François Dumont <fdumont@gcc.gnu.org> + + PR libstdc++/87135 + * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt): + Use __builtin_floor to compute _M_next_resize. + * testsuite/23_containers/unordered_set/hash_policy/71181.cc: Adapt. + * testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc: + Adapt. + 2018-09-21 Jonathan Wakely <jwakely@redhat.com> * testsuite/26_numerics/headers/cmath/hypot-long-double.cc: Remove. diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc index 4627676..b9b11ff 100644 --- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc +++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc @@ -52,7 +52,7 @@ namespace __detail if (__n < sizeof(__fast_bkt)) { _M_next_resize = - __builtin_ceil(__fast_bkt[__n] * (long double)_M_max_load_factor); + __builtin_floor(__fast_bkt[__n] * (long double)_M_max_load_factor); return __fast_bkt[__n]; } @@ -75,7 +75,7 @@ namespace __detail _M_next_resize = std::size_t(-1); else _M_next_resize = - __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor); + __builtin_floor(*__next_bkt * (long double)_M_max_load_factor); return *__next_bkt; } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc index 0270ea5..ba783d2 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc @@ -30,7 +30,7 @@ template<typename _USet> auto bkts = us.bucket_count(); for (int i = 0; i != threshold; ++i) { - if (i == nb_reserved) + if (i >= nb_reserved) { nb_reserved = bkts; us.reserve(nb_reserved); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc index 7110a3a..916c5ad 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc @@ -26,20 +26,22 @@ void test01() { std::__detail::_Prime_rehash_policy policy; - for (std::size_t i = 1;;) + // Starts at 4 because 2 & 3 are two consecutives primes that make this test + // fail. + for (std::size_t i = 4;;) { auto nxt = policy._M_next_bkt(i); - if (nxt == i) + if (nxt <= i) { - // Equals only when reaching max. - constexpr auto mx = std::numeric_limits<std::size_t>::max() - 1; + // Lower or equals only when reaching max prime. + constexpr auto mx = std::numeric_limits<std::size_t>::max(); VERIFY( nxt == policy._M_next_bkt(mx) ); break; } VERIFY( nxt > i ); - i = nxt; + i = nxt + 1; } } |