PR libstdc++/78389 fix backwards size adjustments.
authorVille Voutilainen <ville.voutilainen@gmail.com>
Mon, 16 Jan 2017 11:36:33 +0000 (13:36 +0200)
committerVille Voutilainen <ville@gcc.gnu.org>
Mon, 16 Jan 2017 11:36:33 +0000 (13:36 +0200)
PR libstdc++/78389
* include/bits/list.tcc (merge(list&&)): Fix backwards size adjustments.
(merge(list&&, _StrictWeakOrdering)): Likewise.
* testsuite/23_containers/list/operations/78389.cc: Add
better test for the sizes.

From-SVN: r244490

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/list.tcc
libstdc++-v3/testsuite/23_containers/list/operations/78389.cc

index 024e1b3314775d633ec1864c9e642b7c439b3aed..998662a64578f6db3f33a3f4e22b51c6e505f79b 100644 (file)
@@ -1,3 +1,11 @@
+2017-01-16  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       PR libstdc++/78389
+       * include/bits/list.tcc (merge(list&&)): Fix backwards size adjustments.
+       (merge(list&&, _StrictWeakOrdering)): Likewise.
+       * testsuite/23_containers/list/operations/78389.cc: Add
+       better test for the sizes.
+
 2017-01-14  Jonathan Wakely  <jwakely@redhat.com>
 
        * testsuite/23_containers/array/specialized_algorithms/swap_cxx17.cc:
index 5be49a839972b4e780b9fb55ebd6d8d68db0d2fc..d80d569eaaf1a7a4a95814d707f93bfc260f4143 100644 (file)
@@ -406,8 +406,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
          __catch(...)
            {
              size_t __dist = std::distance(__first2, __last2);
-             this->_M_inc_size(__dist);
-             __x._M_set_size(__orig_size - __dist);
+             this->_M_inc_size(__orig_size - __dist);
+             __x._M_set_size(__dist);
              __throw_exception_again;
            }
        }
@@ -454,8 +454,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
            __catch(...)
              {
                size_t __dist = std::distance(__first2, __last2);
-               this->_M_inc_size(__dist);
-               __x._M_set_size(__orig_size - __dist);
+               this->_M_inc_size(__orig_size - __dist);
+               __x._M_set_size(__dist);
                __throw_exception_again;
              }
          }
index 1cf9b0c58d1ff5949d2be805ac28a681af3ba59c..4d8b7d2818b4bc7f81dc52fef7496a9d83f6d981 100644 (file)
@@ -57,18 +57,20 @@ int main()
   std::list<int> a{1, 2, 3, 4};
   std::list<int> b{5, 6, 7, 8, 9, 10, 11, 12};
   try {
-    a.merge(b, ThrowingComparator{5});
+    a.merge(b, ThrowingComparator{4});
   } catch (...) {
   }
-  VERIFY(a.size() == 8 && b.size() == 4);
+  VERIFY(a.size() == std::distance(a.begin(), a.end()) &&
+        b.size() == std::distance(b.begin(), b.end()));
   std::list<X> ax{1, 2, 3, 4};
   std::list<X> bx{5, 6, 7, 8, 9, 10, 11, 12};
-  throw_after_X = 5;
+  throw_after_X = 4;
   try {
     ax.merge(bx);
   } catch (...) {
   }
-  VERIFY(ax.size() == 8 && bx.size() == 4);
+  VERIFY(ax.size() == std::distance(ax.begin(), ax.end()) &&
+        bx.size() == std::distance(bx.begin(), bx.end()));
   std::list<int> ay{5, 6, 7, 8, 9, 10, 11, 12};
   try {
     ay.sort(ThrowingComparator{5});