From: Paolo Carlini Date: Thu, 24 Apr 2008 17:03:13 +0000 (+0000) Subject: re PR libstdc++/35969 (GLIBCXX_DEBUG: list::merge triggers bad assert) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=27995ee1b8257f1ad72929bdbfff8ebf06d052f9;p=gcc.git re PR libstdc++/35969 (GLIBCXX_DEBUG: list::merge triggers bad assert) 2008-04-24 Paolo Carlini PR libstdc++/35969 * include/debug/list (merge): Use _M_transfer_iter, consistently with the splice members. * testsuite/23_containers/list/operations/35969.cc: New. * testsuite/23_containers/list/operators: Rename to testsuite/23_containers/list/operations. From-SVN: r134642 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cdf96562862..8b16606df6a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2008-04-24 Paolo Carlini + + PR libstdc++/35969 + * include/debug/list (merge): Use _M_transfer_iter, consistently + with the splice members. + * testsuite/23_containers/list/operations/35969.cc: New. + + * testsuite/23_containers/list/operators: Rename to + testsuite/23_containers/list/operations. + 2008-04-24 Benjamin Kosnik * acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): Check for set of diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index b071d4fcdd6..d0797e9bf46 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -1,6 +1,6 @@ // Debugging list implementation -*- C++ -*- -// Copyright (C) 2003, 2004, 2005, 2006, 2007 +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -527,14 +527,19 @@ namespace __debug merge(list& __x) #endif { - __glibcxx_check_sorted(_Base::begin(), _Base::end()); - __glibcxx_check_sorted(__x.begin().base(), __x.end().base()); - for (iterator __tmp = __x.begin(); __tmp != __x.end(); ) + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 300. list::merge() specification incomplete + if (this != &__x) { - iterator __victim = __tmp++; - __victim._M_attach(&__x); + __glibcxx_check_sorted(_Base::begin(), _Base::end()); + __glibcxx_check_sorted(__x.begin().base(), __x.end().base()); + for (iterator __tmp = __x.begin(); __tmp != __x.end();) + { + iterator __victim = __tmp++; + this->_M_transfer_iter(__victim); + } + _Base::merge(_GLIBCXX_MOVE(__x._M_base())); } - _Base::merge(_GLIBCXX_MOVE(__x._M_base())); } template @@ -545,15 +550,21 @@ namespace __debug merge(list& __x, _Compare __comp) #endif { - __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp); - __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(), - __comp); - for (iterator __tmp = __x.begin(); __tmp != __x.end(); ) + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 300. list::merge() specification incomplete + if (this != &__x) { - iterator __victim = __tmp++; - __victim._M_attach(&__x); + __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), + __comp); + __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(), + __comp); + for (iterator __tmp = __x.begin(); __tmp != __x.end();) + { + iterator __victim = __tmp++; + this->_M_transfer_iter(__victim); + } + _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp); } - _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp); } void diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/1.cc b/libstdc++-v3/testsuite/23_containers/list/operations/1.cc new file mode 100644 index 00000000000..1bc91914f44 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/1.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.2.4 list operations [lib.list.ops] + +#include +#include + +bool test __attribute__((unused)) = true; + +// splice(p, x) + remove + reverse +void +test01() +{ + const int K = 417; + const int A[] = {1, 2, 3, 4, 5}; + const int B[] = {K, K, K, K, K}; + const std::size_t N = sizeof(A) / sizeof(int); + const std::size_t M = sizeof(B) / sizeof(int); + + std::list list0101(A, A + N); + std::list list0102(B, B + M); + std::list::iterator p = list0101.begin(); + + VERIFY(list0101.size() == N); + VERIFY(list0102.size() == M); + + ++p; + list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5] + VERIFY(list0101.size() == N + M); + VERIFY(list0102.size() == 0); + + // remove range from middle + list0101.remove(K); + VERIFY(list0101.size() == N); + + // remove first element + list0101.remove(1); + VERIFY(list0101.size() == N - 1); + + // remove last element + list0101.remove(5); + VERIFY(list0101.size() == N - 2); + + // reverse + list0101.reverse(); + p = list0101.begin(); + VERIFY(*p == 4); ++p; + VERIFY(*p == 3); ++p; + VERIFY(*p == 2); ++p; + VERIFY(p == list0101.end()); +} + +int main(void) +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/2.cc b/libstdc++-v3/testsuite/23_containers/list/operations/2.cc new file mode 100644 index 00000000000..dc41e12c511 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/2.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.2.4 list operations [lib.list.ops] + +#include +#include + +bool test __attribute__((unused)) = true; + +// splice(p, x, i) + remove_if + operator== +void +test02() +{ + const int A[] = {1, 2, 3, 4, 5}; + const int B[] = {2, 1, 3, 4, 5}; + const int C[] = {1, 3, 4, 5, 2}; + const int N = sizeof(A) / sizeof(int); + std::list list0201(A, A + N); + std::list list0202(A, A + N); + std::list list0203(B, B + N); + std::list list0204(C, C + N); + std::list::iterator i = list0201.begin(); + + // result should be unchanged + list0201.splice(list0201.begin(), list0201, i); + VERIFY(list0201 == list0202); + + // result should be [2 1 3 4 5] + ++i; + list0201.splice(list0201.begin(), list0201, i); + VERIFY(list0201 != list0202); + VERIFY(list0201 == list0203); + + // result should be [1 3 4 5 2] + list0201.splice(list0201.end(), list0201, i); + VERIFY(list0201 == list0204); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/3.cc b/libstdc++-v3/testsuite/23_containers/list/operations/3.cc new file mode 100644 index 00000000000..9e0d3f9b561 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/3.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.2.4 list operations [lib.list.ops] + +#include +#include + +bool test __attribute__((unused)) = true; + +// splice(p, x, f, l) + sort + merge + unique +void +test03() +{ + const int A[] = {103, 203, 603, 303, 403, 503}; + const int B[] = {417, 417, 417, 417, 417}; + const int E[] = {103, 417, 417, 203, 603, 303, 403, 503}; + const int F[] = {103, 203, 303, 403, 417, 417, 503, 603}; + const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603}; + const int D[] = {103, 203, 303, 403, 417, 503, 603}; + const int N = sizeof(A) / sizeof(int); + const int M = sizeof(B) / sizeof(int); + const int P = sizeof(C) / sizeof(int); + const int Q = sizeof(D) / sizeof(int); + const int R = sizeof(E) / sizeof(int); + + std::list list0301(A, A + N); + std::list list0302(B, B + M); + std::list list0303(C, C + P); + std::list list0304(D, D + Q); + std::list list0305(E, E + R); + std::list list0306(F, F + R); + std::list::iterator p = list0301.begin(); + std::list::iterator q = list0302.begin(); + + ++p; ++q; ++q; + list0301.splice(p, list0302, list0302.begin(), q); + VERIFY(list0301 == list0305); + VERIFY(list0301.size() == N + 2); + VERIFY(list0302.size() == M - 2); + + list0301.sort(); + VERIFY(list0301 == list0306); + + list0301.merge(list0302); + VERIFY(list0301.size() == N + M); + VERIFY(list0302.size() == 0); + VERIFY(list0301 == list0303); + + list0301.unique(); + VERIFY(list0301 == list0304); +} + +int main(void) +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/35969.cc b/libstdc++-v3/testsuite/23_containers/list/operations/35969.cc new file mode 100644 index 00000000000..97747ad9a6e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/35969.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.2.4 list operations [lib.list.ops] + +// { dg-options "-D_GLIBCXX_DEBUG" } + +#include +#include + +// libstdc++/35969 +void test01() +{ + { + std::list list1; + std::list list2; + + for(int i = 0; i < 10; ++i) + { + list1.push_back(i); + list2.push_back(10 - i); + } + + list1.sort(); + list2.sort(); + + std::list::iterator node_of_interest = list2.begin(); + + list1.splice(list1.begin(), list2, node_of_interest); + list2.splice(list2.begin(), list1, node_of_interest); + + list1.merge(list2); + + list2.splice(list2.begin(), list1, node_of_interest); + } + + { + std::list list1; + std::list list2; + + for(int i = 0; i < 10; ++i) + { + list1.push_back(i); + list2.push_back(10 - i); + } + + list1.sort(); + list2.sort(); + + std::list::iterator node_of_interest = list2.begin(); + + list1.splice(list1.begin(), list2, node_of_interest); + list2.splice(list2.begin(), list1, node_of_interest); + + list1.merge(list2, std::less()); + + list2.splice(list2.begin(), list1, node_of_interest); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/4.cc b/libstdc++-v3/testsuite/23_containers/list/operations/4.cc new file mode 100644 index 00000000000..2c355145cbe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/4.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.2.4 list operations [lib.list.ops] + +#include +#include + +bool test __attribute__((unused)) = true; + +// A comparison predicate to order by rightmost digit. Tracks call counts for +// performance checks. +struct CompLastLt +{ + bool operator()(const int x, const int y) + { ++itsCount; return x % 10 < y % 10; } + static int count() { return itsCount; } + static void reset() { itsCount = 0; } + static int itsCount; +}; + +int CompLastLt::itsCount; + +struct CompLastEq +{ + bool operator()(const int x, const int y) + { ++itsCount; return x % 10 == y % 10; } + static int count() { return itsCount; } + static void reset() { itsCount = 0; } + static int itsCount; +}; + +int CompLastEq::itsCount; + +// sort(pred) + merge(pred) + unique(pred) +// also checks performance requirements +void +test04() +{ + const int A[] = {1, 2, 3, 4, 5, 6}; + const int B[] = {12, 15, 13, 14, 11}; + const int C[] = {11, 12, 13, 14, 15}; + const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6}; + const int N = sizeof(A) / sizeof(int); + const int M = sizeof(B) / sizeof(int); + const int Q = sizeof(D) / sizeof(int); + + std::list list0401(A, A + N); + std::list list0402(B, B + M); + std::list list0403(C, C + M); + std::list list0404(D, D + Q); + std::list list0405(A, A + N); + + // sort B + CompLastLt lt; + + CompLastLt::reset(); + list0402.sort(lt); + VERIFY(list0402 == list0403); + + CompLastLt::reset(); + list0401.merge(list0402, lt); + VERIFY(list0401 == list0404); +#ifndef _GLIBCXX_DEBUG + VERIFY(lt.count() <= (N + M - 1)); +#endif + + CompLastEq eq; + + CompLastEq::reset(); + list0401.unique(eq); + VERIFY(list0401 == list0405); +#ifndef _GLIBCXX_DEBUG + VERIFY(eq.count() == (N + M - 1)); +#endif +} + +int main() +{ + test04(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/5.cc b/libstdc++-v3/testsuite/23_containers/list/operations/5.cc new file mode 100644 index 00000000000..22f504691d9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/5.cc @@ -0,0 +1,141 @@ +// 2006-01-19 Paolo Carlini + +// Copyright (C) 2006 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.2.4 list operations [lib.list.ops] + +#include +#include +#include +#include + +// Check the splice (and merge) bits of N1599. +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef __gnu_test::uneq_allocator my_alloc; + typedef std::list my_list; + + const int data1[] = {1, 2, 3, 4, 5}; + const int data2[] = {6, 7, 8, 9, 10}; + const size_t N1 = sizeof(data1) / sizeof(int); + const size_t N2 = sizeof(data2) / sizeof(int); + + my_alloc alloc01(1), alloc02(2); + + my_list l01(data1, data1 + N1, alloc01); + const my_list l01_ref = l01; + + my_list l02(data2, data2 + N2, alloc02); + const my_list l02_ref = l02; + + bool catched = false; + + try + { + l01.splice(l01.begin(), l02); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); + + catched = false; + try + { + l01.splice(l01.begin(), l02, l02.begin()); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); + + catched = false; + try + { + l01.splice(l01.begin(), l02, l02.begin(), l02.end()); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); + + catched = false; + try + { + l01.merge(l02); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); + + catched = false; + try + { + l01.merge(l02, std::less()); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operators/1.cc b/libstdc++-v3/testsuite/23_containers/list/operators/1.cc deleted file mode 100644 index 1bc91914f44..00000000000 --- a/libstdc++-v3/testsuite/23_containers/list/operators/1.cc +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without Pred the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// 23.2.2.4 list operations [lib.list.ops] - -#include -#include - -bool test __attribute__((unused)) = true; - -// splice(p, x) + remove + reverse -void -test01() -{ - const int K = 417; - const int A[] = {1, 2, 3, 4, 5}; - const int B[] = {K, K, K, K, K}; - const std::size_t N = sizeof(A) / sizeof(int); - const std::size_t M = sizeof(B) / sizeof(int); - - std::list list0101(A, A + N); - std::list list0102(B, B + M); - std::list::iterator p = list0101.begin(); - - VERIFY(list0101.size() == N); - VERIFY(list0102.size() == M); - - ++p; - list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5] - VERIFY(list0101.size() == N + M); - VERIFY(list0102.size() == 0); - - // remove range from middle - list0101.remove(K); - VERIFY(list0101.size() == N); - - // remove first element - list0101.remove(1); - VERIFY(list0101.size() == N - 1); - - // remove last element - list0101.remove(5); - VERIFY(list0101.size() == N - 2); - - // reverse - list0101.reverse(); - p = list0101.begin(); - VERIFY(*p == 4); ++p; - VERIFY(*p == 3); ++p; - VERIFY(*p == 2); ++p; - VERIFY(p == list0101.end()); -} - -int main(void) -{ - test01(); - return 0; -} - diff --git a/libstdc++-v3/testsuite/23_containers/list/operators/2.cc b/libstdc++-v3/testsuite/23_containers/list/operators/2.cc deleted file mode 100644 index dc41e12c511..00000000000 --- a/libstdc++-v3/testsuite/23_containers/list/operators/2.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without Pred the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// 23.2.2.4 list operations [lib.list.ops] - -#include -#include - -bool test __attribute__((unused)) = true; - -// splice(p, x, i) + remove_if + operator== -void -test02() -{ - const int A[] = {1, 2, 3, 4, 5}; - const int B[] = {2, 1, 3, 4, 5}; - const int C[] = {1, 3, 4, 5, 2}; - const int N = sizeof(A) / sizeof(int); - std::list list0201(A, A + N); - std::list list0202(A, A + N); - std::list list0203(B, B + N); - std::list list0204(C, C + N); - std::list::iterator i = list0201.begin(); - - // result should be unchanged - list0201.splice(list0201.begin(), list0201, i); - VERIFY(list0201 == list0202); - - // result should be [2 1 3 4 5] - ++i; - list0201.splice(list0201.begin(), list0201, i); - VERIFY(list0201 != list0202); - VERIFY(list0201 == list0203); - - // result should be [1 3 4 5 2] - list0201.splice(list0201.end(), list0201, i); - VERIFY(list0201 == list0204); -} - -int main() -{ - test02(); - return 0; -} diff --git a/libstdc++-v3/testsuite/23_containers/list/operators/3.cc b/libstdc++-v3/testsuite/23_containers/list/operators/3.cc deleted file mode 100644 index 9e0d3f9b561..00000000000 --- a/libstdc++-v3/testsuite/23_containers/list/operators/3.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without Pred the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// 23.2.2.4 list operations [lib.list.ops] - -#include -#include - -bool test __attribute__((unused)) = true; - -// splice(p, x, f, l) + sort + merge + unique -void -test03() -{ - const int A[] = {103, 203, 603, 303, 403, 503}; - const int B[] = {417, 417, 417, 417, 417}; - const int E[] = {103, 417, 417, 203, 603, 303, 403, 503}; - const int F[] = {103, 203, 303, 403, 417, 417, 503, 603}; - const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603}; - const int D[] = {103, 203, 303, 403, 417, 503, 603}; - const int N = sizeof(A) / sizeof(int); - const int M = sizeof(B) / sizeof(int); - const int P = sizeof(C) / sizeof(int); - const int Q = sizeof(D) / sizeof(int); - const int R = sizeof(E) / sizeof(int); - - std::list list0301(A, A + N); - std::list list0302(B, B + M); - std::list list0303(C, C + P); - std::list list0304(D, D + Q); - std::list list0305(E, E + R); - std::list list0306(F, F + R); - std::list::iterator p = list0301.begin(); - std::list::iterator q = list0302.begin(); - - ++p; ++q; ++q; - list0301.splice(p, list0302, list0302.begin(), q); - VERIFY(list0301 == list0305); - VERIFY(list0301.size() == N + 2); - VERIFY(list0302.size() == M - 2); - - list0301.sort(); - VERIFY(list0301 == list0306); - - list0301.merge(list0302); - VERIFY(list0301.size() == N + M); - VERIFY(list0302.size() == 0); - VERIFY(list0301 == list0303); - - list0301.unique(); - VERIFY(list0301 == list0304); -} - -int main(void) -{ - test03(); - return 0; -} diff --git a/libstdc++-v3/testsuite/23_containers/list/operators/4.cc b/libstdc++-v3/testsuite/23_containers/list/operators/4.cc deleted file mode 100644 index 2c355145cbe..00000000000 --- a/libstdc++-v3/testsuite/23_containers/list/operators/4.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without Pred the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// 23.2.2.4 list operations [lib.list.ops] - -#include -#include - -bool test __attribute__((unused)) = true; - -// A comparison predicate to order by rightmost digit. Tracks call counts for -// performance checks. -struct CompLastLt -{ - bool operator()(const int x, const int y) - { ++itsCount; return x % 10 < y % 10; } - static int count() { return itsCount; } - static void reset() { itsCount = 0; } - static int itsCount; -}; - -int CompLastLt::itsCount; - -struct CompLastEq -{ - bool operator()(const int x, const int y) - { ++itsCount; return x % 10 == y % 10; } - static int count() { return itsCount; } - static void reset() { itsCount = 0; } - static int itsCount; -}; - -int CompLastEq::itsCount; - -// sort(pred) + merge(pred) + unique(pred) -// also checks performance requirements -void -test04() -{ - const int A[] = {1, 2, 3, 4, 5, 6}; - const int B[] = {12, 15, 13, 14, 11}; - const int C[] = {11, 12, 13, 14, 15}; - const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6}; - const int N = sizeof(A) / sizeof(int); - const int M = sizeof(B) / sizeof(int); - const int Q = sizeof(D) / sizeof(int); - - std::list list0401(A, A + N); - std::list list0402(B, B + M); - std::list list0403(C, C + M); - std::list list0404(D, D + Q); - std::list list0405(A, A + N); - - // sort B - CompLastLt lt; - - CompLastLt::reset(); - list0402.sort(lt); - VERIFY(list0402 == list0403); - - CompLastLt::reset(); - list0401.merge(list0402, lt); - VERIFY(list0401 == list0404); -#ifndef _GLIBCXX_DEBUG - VERIFY(lt.count() <= (N + M - 1)); -#endif - - CompLastEq eq; - - CompLastEq::reset(); - list0401.unique(eq); - VERIFY(list0401 == list0405); -#ifndef _GLIBCXX_DEBUG - VERIFY(eq.count() == (N + M - 1)); -#endif -} - -int main() -{ - test04(); - return 0; -} - diff --git a/libstdc++-v3/testsuite/23_containers/list/operators/5.cc b/libstdc++-v3/testsuite/23_containers/list/operators/5.cc deleted file mode 100644 index 22f504691d9..00000000000 --- a/libstdc++-v3/testsuite/23_containers/list/operators/5.cc +++ /dev/null @@ -1,141 +0,0 @@ -// 2006-01-19 Paolo Carlini - -// Copyright (C) 2006 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without Pred the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// 23.2.2.4 list operations [lib.list.ops] - -#include -#include -#include -#include - -// Check the splice (and merge) bits of N1599. -void -test01() -{ - bool test __attribute__((unused)) = true; - - typedef __gnu_test::uneq_allocator my_alloc; - typedef std::list my_list; - - const int data1[] = {1, 2, 3, 4, 5}; - const int data2[] = {6, 7, 8, 9, 10}; - const size_t N1 = sizeof(data1) / sizeof(int); - const size_t N2 = sizeof(data2) / sizeof(int); - - my_alloc alloc01(1), alloc02(2); - - my_list l01(data1, data1 + N1, alloc01); - const my_list l01_ref = l01; - - my_list l02(data2, data2 + N2, alloc02); - const my_list l02_ref = l02; - - bool catched = false; - - try - { - l01.splice(l01.begin(), l02); - } - catch(std::runtime_error&) - { - catched = true; - } - catch(...) - { - VERIFY( false ); - } - VERIFY( catched ); - VERIFY( l01 == l01_ref ); - VERIFY( l02 == l02_ref ); - - catched = false; - try - { - l01.splice(l01.begin(), l02, l02.begin()); - } - catch(std::runtime_error&) - { - catched = true; - } - catch(...) - { - VERIFY( false ); - } - VERIFY( catched ); - VERIFY( l01 == l01_ref ); - VERIFY( l02 == l02_ref ); - - catched = false; - try - { - l01.splice(l01.begin(), l02, l02.begin(), l02.end()); - } - catch(std::runtime_error&) - { - catched = true; - } - catch(...) - { - VERIFY( false ); - } - VERIFY( catched ); - VERIFY( l01 == l01_ref ); - VERIFY( l02 == l02_ref ); - - catched = false; - try - { - l01.merge(l02); - } - catch(std::runtime_error&) - { - catched = true; - } - catch(...) - { - VERIFY( false ); - } - VERIFY( catched ); - VERIFY( l01 == l01_ref ); - VERIFY( l02 == l02_ref ); - - catched = false; - try - { - l01.merge(l02, std::less()); - } - catch(std::runtime_error&) - { - catched = true; - } - catch(...) - { - VERIFY( false ); - } - VERIFY( catched ); - VERIFY( l01 == l01_ref ); - VERIFY( l02 == l02_ref ); -} - -int main() -{ - test01(); - return 0; -}