From: Ville Voutilainen Date: Mon, 16 Jan 2017 11:36:33 +0000 (+0200) Subject: PR libstdc++/78389 fix backwards size adjustments. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=53426b63b3c99db36df3c83bdbd71d5f4f514de2;p=gcc.git PR libstdc++/78389 fix backwards size adjustments. 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 024e1b33147..998662a6457 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2017-01-16 Ville Voutilainen + + 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 * testsuite/23_containers/array/specialized_algorithms/swap_cxx17.cc: diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index 5be49a83997..d80d569eaaf 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -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; } } diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc b/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc index 1cf9b0c58d1..4d8b7d2818b 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc @@ -57,18 +57,20 @@ int main() std::list a{1, 2, 3, 4}; std::list 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 ax{1, 2, 3, 4}; std::list 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 ay{5, 6, 7, 8, 9, 10, 11, 12}; try { ay.sort(ThrowingComparator{5});