re PR libstdc++/87135 ([C++17] unordered containers violate iterator validity require...
authorFrançois Dumont <fdumont@gcc.gnu.org>
Fri, 21 Sep 2018 20:39:07 +0000 (20:39 +0000)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Fri, 21 Sep 2018 20:39:07 +0000 (20:39 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/src/c++11/hashtable_c++0x.cc
libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc
libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc

index 161ea11a617fd5b6c8d5b4d745879ac4a2f98a6d..e64f11c1b14428b50b15c52b8b458401b29b49f7 100644 (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.
index 462767612f0aacb800618bfe61c8bf735e9ae371..b9b11ff4385ecfddc4896680d1ca6fd39bc88d6d 100644 (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;
   }
index 0270ea52b9c70e9aa1735a6336821ee4344479f2..ba783d26847c6383aaa92481b540094afda7456e 100644 (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);
index 7110a3afb39d787aae6f6a20ca8f749049947fea..916c5ad702c0a03b0f4035128ed7b648780fc2e5 100644 (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;
     }
 }