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
This commit is contained in:
François Dumont 2018-09-21 20:39:07 +00:00
parent 35b66f3043
commit 9b29794962
4 changed files with 19 additions and 8 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}
}