On 15 January 2017 at 19:01, Ville Voutilainen <ville.voutilai...@gmail.com> wrote: > On 15 January 2017 at 18:42, Tim Song <t.canens....@gmail.com> wrote: >> On rereading the patch today, the size calculation for merge() appears >> to be backwards. [__first2, __last2) consists of the nodes not >> transferred into *this, so the new size of __x should be __dist while >> this->size() should be incremented by (__orig_size - __dist). > > Ah, yes, I'm an idiot. Fixing...
2017-01-15 Ville Voutilainen <ville.voutilai...@gmail.com> PR libstdc++/78389 Fix backwards size adjustments. * 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.
diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index 5be49a8..d80d569 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 1cf9b0c..3002ba6 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc @@ -61,6 +61,8 @@ int main() } 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; @@ -69,6 +71,8 @@ int main() } 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});