summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/23_containers/list/modifiers
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/23_containers/list/modifiers
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/list/modifiers')
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc25
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/1.h116
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/1_c++0x.cc27
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc25
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/2.h89
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc25
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/3.h121
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc31
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h90
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc35
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h58
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc31
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h127
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc31
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h156
15 files changed, 987 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc
new file mode 100644
index 000000000..4d56b154a
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "1.h"
+#include <list>
+
+int main()
+{
+ modifiers1<std::list<__gnu_test::copy_tracker> >();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/1.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.h
new file mode 100644
index 000000000..2abc063e1
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.h
@@ -0,0 +1,116 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.2.3 list modifiers [lib.list.modifiers]
+
+#include <testsuite_hooks.h>
+
+// range and fill insert/erase + clear
+// missing: o fill insert disguised as a range insert in all its variants
+// o exception effects
+template<typename _Tp>
+void
+modifiers1()
+{
+ bool test __attribute__((unused)) = true;
+ typedef _Tp list_type;
+ typedef typename list_type::iterator iterator;
+ typedef typename list_type::value_type value_type;
+
+ using __gnu_test::copy_constructor;
+ using __gnu_test::destructor;
+
+ list_type list0301;
+ value_type::reset();
+
+ // fill insert at beginning of list / empty list
+ list0301.insert(list0301.begin(), 3, value_type(11)); // should be [11 11 11]
+ VERIFY(list0301.size() == 3);
+ VERIFY(copy_constructor::count() == 3);
+
+ // save iterators to verify post-insert validity
+ iterator b = list0301.begin();
+ iterator m = list0301.end(); --m;
+ iterator e = list0301.end();
+
+ // fill insert at end of list
+ value_type::reset();
+ list0301.insert(list0301.end(), 3, value_type(13)); // should be [11 11 11 13 13 13]
+ VERIFY(list0301.size() == 6);
+ VERIFY(copy_constructor::count() == 3);
+ VERIFY(b == list0301.begin() && b->id() == 11);
+ VERIFY(e == list0301.end());
+ VERIFY(m->id() == 11);
+
+ // fill insert in the middle of list
+ ++m;
+ value_type::reset();
+ list0301.insert(m, 3, value_type(12)); // should be [11 11 11 12 12 12 13 13 13]
+ VERIFY(list0301.size() == 9);
+ VERIFY(copy_constructor::count() == 3);
+ VERIFY(b == list0301.begin() && b->id() == 11);
+ VERIFY(e == list0301.end());
+ VERIFY(m->id() == 13);
+
+ // single erase
+ value_type::reset();
+ m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
+ VERIFY(list0301.size() == 8);
+ VERIFY(destructor::count() == 1);
+ VERIFY(b == list0301.begin() && b->id() == 11);
+ VERIFY(e == list0301.end());
+ VERIFY(m->id() == 13);
+
+ // range erase
+ value_type::reset();
+ m = list0301.erase(list0301.begin(), m); // should be [13 13]
+ VERIFY(list0301.size() == 2);
+ VERIFY(destructor::count() == 6);
+ VERIFY(m->id() == 13);
+
+ // range fill at beginning
+ const int A[] = {321, 322, 333};
+ const int N = sizeof(A) / sizeof(int);
+ value_type::reset();
+ b = list0301.begin();
+ list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
+ VERIFY(list0301.size() == 5);
+ VERIFY(copy_constructor::count() == 3);
+ VERIFY(m->id() == 13);
+
+ // range fill at end
+ value_type::reset();
+ list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
+ VERIFY(list0301.size() == 8);
+ VERIFY(copy_constructor::count() == 3);
+ VERIFY(e == list0301.end());
+ VERIFY(m->id() == 13);
+
+ // range fill in middle
+ value_type::reset();
+ list0301.insert(m, A, A + N);
+ VERIFY(list0301.size() == 11);
+ VERIFY(copy_constructor::count() == 3);
+ VERIFY(e == list0301.end());
+ VERIFY(m->id() == 13);
+
+ value_type::reset();
+ list0301.clear();
+ VERIFY(list0301.size() == 0);
+ VERIFY(destructor::count() == 11);
+ VERIFY(e == list0301.end());
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/1_c++0x.cc
new file mode 100644
index 000000000..dea0d4c44
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/1_c++0x.cc
@@ -0,0 +1,27 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "1.h"
+#include <list>
+
+int main()
+{
+ modifiers1<std::list<__gnu_test::copy_tracker> >();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc
new file mode 100644
index 000000000..1879ed2e5
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "2.h"
+#include <list>
+
+int main()
+{
+ modifiers2<std::list<__gnu_test::copy_tracker> >();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/2.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.h
new file mode 100644
index 000000000..b25467bdb
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.h
@@ -0,0 +1,89 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.2.3 list modifiers [lib.list.modifiers]
+
+#include <testsuite_hooks.h>
+
+// general single insert/erase + swap
+template<typename _Tp>
+void
+modifiers2()
+{
+ bool test __attribute__((unused)) = true;
+ typedef _Tp list_type;
+ typedef typename list_type::value_type value_type;
+ typedef typename list_type::iterator iterator;
+ typedef typename list_type::const_iterator const_iterator;
+
+ using __gnu_test::copy_constructor;
+ using __gnu_test::destructor;
+
+ list_type list0201;
+ value_type::reset();
+
+ list0201.insert(list0201.begin(), value_type(1)); // list should be [1]
+ VERIFY(list0201.size() == 1);
+ VERIFY(copy_constructor::count() == 1);
+
+ list0201.insert(list0201.end(), value_type(2)); // list should be [1 2]
+ VERIFY(list0201.size() == 2);
+ VERIFY(copy_constructor::count() == 2);
+
+ iterator i = list0201.begin();
+ const_iterator j = i;
+ VERIFY(i->id() == 1); ++i;
+ VERIFY(i->id() == 2);
+
+ list0201.insert(i, value_type(3)); // list should be [1 3 2]
+ VERIFY(list0201.size() == 3);
+ VERIFY(copy_constructor::count() == 3);
+
+ const_iterator k = i;
+ VERIFY(i->id() == 2); --i;
+ VERIFY(i->id() == 3); --i;
+ VERIFY(i->id() == 1);
+ VERIFY(j->id() == 1);
+
+ ++i; // will point to '3'
+ value_type::reset();
+ list0201.erase(i); // should be [1 2]
+ VERIFY(list0201.size() == 2);
+ VERIFY(destructor::count() == 1);
+ VERIFY(k->id() == 2);
+ VERIFY(j->id() == 1);
+
+ list_type list0202;
+ value_type::reset();
+ VERIFY(list0202.size() == 0);
+ VERIFY(copy_constructor::count() == 0);
+ VERIFY(destructor::count() == 0);
+
+ // member swap
+ list0202.swap(list0201);
+ VERIFY(list0201.size() == 0);
+ VERIFY(list0202.size() == 2);
+ VERIFY(copy_constructor::count() == 0);
+ VERIFY(destructor::count() == 0);
+
+ // specialized swap
+ swap(list0201, list0202);
+ VERIFY(list0201.size() == 2);
+ VERIFY(list0202.size() == 0);
+ VERIFY(copy_constructor::count() == 0);
+ VERIFY(destructor::count() == 0);
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc
new file mode 100644
index 000000000..990cf227c
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "3.h"
+#include <list>
+
+int main()
+{
+ modifiers3<std::list<__gnu_test::copy_tracker> >();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/3.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.h
new file mode 100644
index 000000000..c4017db49
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.h
@@ -0,0 +1,121 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.2.3 list modifiers [lib.list.modifiers]
+
+#include <testsuite_hooks.h>
+
+// This test verifies the following.
+//
+// 23.2.2.3 void push_front(const T& x)
+// 23.2.2.3 void push_back(const T& x)
+// 23.2.2.3 (1) iterator and reference non-invalidation
+// 23.2.2.3 (1) exception effects
+// 23.2.2.3 (2) complexity requirements
+//
+// 23.2.2.3 void pop_front()
+// 23.2.2.3 void pop_back()
+// 23.2.2.3 (3) iterator and reference non-invalidation
+// 23.2.2.3 (5) complexity requirements
+//
+// 23.2.2 const_iterator begin() const
+// 23.2.2 iterator end()
+// 23.2.2 const_reverse_iterator rbegin() const
+// 23.2.2 _reference front()
+// 23.2.2 const_reference front() const
+// 23.2.2 reference back()
+// 23.2.2 const_reference back() const
+//
+template<typename _Tp>
+void
+modifiers3()
+{
+ bool test __attribute__((unused)) = true;
+ typedef _Tp list_type;
+ typedef typename list_type::iterator iterator;
+ typedef typename list_type::value_type value_type;
+ typedef typename list_type::const_iterator const_iterator;
+ typedef typename list_type::const_reverse_iterator const_reverse_iterator;
+
+ using __gnu_test::copy_constructor;
+ using __gnu_test::destructor;
+
+ list_type list0101;
+ const_iterator i;
+ const_reverse_iterator j;
+ iterator k;
+ value_type::reset();
+
+ list0101.push_back(value_type(1)); // list should be [1]
+ VERIFY(list0101.size() == 1);
+ VERIFY(copy_constructor::count() == 1);
+
+ k = list0101.end();
+ --k;
+ VERIFY(k->id() == 1);
+ VERIFY(k->id() == list0101.front().id());
+ VERIFY(k->id() == list0101.back().id());
+
+ list0101.push_front(value_type(2)); // list should be [2 1]
+ VERIFY(list0101.size() == 2);
+ VERIFY(copy_constructor::count() == 2);
+ VERIFY(k->id() == 1);
+
+ list0101.push_back(value_type(3)); // list should be [2 1 3]
+ VERIFY(list0101.size() == 3);
+ VERIFY(copy_constructor::count() == 3);
+ VERIFY(k->id() == 1);
+
+ try
+ {
+ list0101.push_back(value_type(4, true));
+ VERIFY(false);
+ }
+ catch (...)
+ {
+ VERIFY(list0101.size() == 3);
+ VERIFY(copy_constructor::count() == 4);
+ }
+
+ i = list0101.begin();
+ VERIFY(i->id() == 2);
+ VERIFY(i->id() == list0101.front().id());
+
+ j = list0101.rbegin();
+ VERIFY(j->id() == 3);
+ VERIFY(j->id() == list0101.back().id());
+
+ ++i;
+ VERIFY(i->id() == 1);
+
+ ++j;
+ VERIFY(j->id() == 1);
+
+ value_type::reset();
+
+ list0101.pop_back(); // list should be [2 1]
+ VERIFY(list0101.size() == 2);
+ VERIFY(destructor::count() == 1);
+ VERIFY(i->id() == 1);
+ VERIFY(k->id() == 1);
+
+ list0101.pop_front(); // list should be [1]
+ VERIFY(list0101.size() == 1);
+ VERIFY(destructor::count() == 2);
+ VERIFY(i->id() == 1);
+ VERIFY(k->id() == 1);
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc
new file mode 100644
index 000000000..6fbcf6c17
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc
@@ -0,0 +1,31 @@
+// { dg-require-time "" }
+
+// Copyright (C) 2005, 2006, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "25288.h"
+#include <list>
+
+int main()
+{
+ typedef int value_type;
+ typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type;
+ typedef std::list<value_type, allocator_type> list_type;
+
+ insert1<list_type>();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h
new file mode 100644
index 000000000..772128d95
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h
@@ -0,0 +1,90 @@
+// Copyright (C) 2005, 2006, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.2.3 list modifiers [lib.list.modifiers]
+
+#include <testsuite_hooks.h>
+#include <ext/throw_allocator.h>
+
+// libstdc++/25288
+template<typename _Tp>
+void insert1()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef _Tp list_type;
+ typedef typename _Tp::value_type value_type;
+ typedef typename _Tp::allocator_type allocator_type;
+ typedef typename _Tp::size_type size_type;
+
+ for (int j = 0; j < 10; ++j)
+ for (int i = 0; i < 10; ++i)
+ {
+ allocator_type alloc1;
+ typename allocator_type::never_adjustor adjust1;
+ list_type list1(alloc1);
+
+ for (int k = 0; k < j; ++k)
+ list1.push_back(value_type(-(k + 1)));
+
+ try
+ {
+ typename allocator_type::always_adjustor adjust2;
+ list1.insert(list1.begin(), 10, 99);
+ VERIFY( false );
+ }
+ catch (__gnu_cxx::forced_error&)
+ {
+ VERIFY( true );
+ }
+ catch (...)
+ {
+ __throw_exception_again;
+ }
+
+ VERIFY( list1.size() == size_type(j) );
+ VERIFY( list1.size() == 0 || list1.back() == -j );
+ VERIFY( list1.size() == 0 || list1.front() == -1 );
+
+ allocator_type alloc2;
+ list_type list2(alloc2);
+
+ const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ for (int k = 0; k < j; ++k)
+ list2.push_back(-(k + 1));
+
+ try
+ {
+ typename allocator_type::always_adjustor adjust3;
+ list2.insert(list2.begin(), data, data + 10);
+ VERIFY( false );
+ }
+ catch (__gnu_cxx::forced_error&)
+ {
+ VERIFY( true );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+
+ VERIFY( list2.size() == size_type(j) );
+ VERIFY( list2.size() == 0 || list2.back() == -j );
+ VERIFY( list2.size() == 0 || list2.front() == -1 );
+ }
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc
new file mode 100644
index 000000000..767640ea9
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2004, 2009 Free Software Foundation
+//
+// 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <list>
+#include "1.h"
+
+namespace std
+{
+ template<>
+ void
+ list<T, allocator<T> >::swap(list<T, allocator<T> >&)
+ { ++swap_calls; }
+}
+
+// See c++/13658 for background info.
+int main()
+{
+ swap11<std::list<T> >();
+ swap12<std::list<T> >();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h
new file mode 100644
index 000000000..64619b424
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2004, 2009 Free Software Foundation
+//
+// 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+struct T { int i; };
+
+int swap_calls;
+
+// Should use list specialization for swap.
+template<typename _Tp>
+void
+swap11()
+{
+ bool test __attribute__((unused)) = true;
+ typedef _Tp list_type;
+
+ list_type A;
+ list_type B;
+ swap_calls = 0;
+ std::swap(A, B);
+ VERIFY(1 == swap_calls);
+}
+
+// Should use list specialization for swap.
+template<typename _Tp>
+void
+swap12()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ typedef _Tp list_type;
+
+ list_type A;
+ list_type B;
+ swap_calls = 0;
+ swap(A, B);
+ VERIFY(1 == swap_calls);
+}
+
+#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
+template class __gnu_cxx::__mt_alloc<std::_List_node<T> >;
+#endif
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc
new file mode 100644
index 000000000..d1faf025f
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc
@@ -0,0 +1,31 @@
+// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <list>
+#include "2.h"
+
+int main()
+{
+ typedef char value_type;
+ typedef __gnu_test::uneq_allocator<value_type> allocator_type;
+ typedef std::list<value_type, allocator_type> list_type;
+
+ swap2<list_type>();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h
new file mode 100644
index 000000000..2cd68f60c
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h
@@ -0,0 +1,127 @@
+// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.2.3 list::swap
+
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+// uneq_allocator as a non-empty allocator.
+template<typename _Tp>
+void
+swap2()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef _Tp list_type;
+ typedef typename list_type::allocator_type allocator_type;
+ typedef typename list_type::size_type size_type;
+
+ const char title01[] = "Rivers of sand";
+ const char title02[] = "Concret PH";
+ const char title03[] = "Sonatas and Interludes for Prepared Piano";
+ const char title04[] = "never as tired as when i'm waking up";
+
+ const size_t N1 = sizeof(title01);
+ const size_t N2 = sizeof(title02);
+ const size_t N3 = sizeof(title03);
+ const size_t N4 = sizeof(title04);
+
+ size_type size01, size02;
+
+ allocator_type alloc01(1);
+
+ list_type lis01(alloc01);
+ size01 = lis01.size();
+ list_type lis02(alloc01);
+ size02 = lis02.size();
+
+ lis01.swap(lis02);
+ VERIFY( lis01.size() == size02 );
+ VERIFY( lis01.empty() );
+ VERIFY( lis02.size() == size01 );
+ VERIFY( lis02.empty() );
+
+ list_type lis03(alloc01);
+ size01 = lis03.size();
+ list_type lis04(title02, title02 + N2, alloc01);
+ size02 = lis04.size();
+
+ lis03.swap(lis04);
+ VERIFY( lis03.size() == size02 );
+ VERIFY( equal(lis03.begin(), lis03.end(), title02) );
+ VERIFY( lis04.size() == size01 );
+ VERIFY( lis04.empty() );
+
+ list_type lis05(title01, title01 + N1, alloc01);
+ size01 = lis05.size();
+ list_type lis06(title02, title02 + N2, alloc01);
+ size02 = lis06.size();
+
+ lis05.swap(lis06);
+ VERIFY( lis05.size() == size02 );
+ VERIFY( equal(lis05.begin(), lis05.end(), title02) );
+ VERIFY( lis06.size() == size01 );
+ VERIFY( equal(lis06.begin(), lis06.end(), title01) );
+
+ list_type lis07(title01, title01 + N1, alloc01);
+ size01 = lis07.size();
+ list_type lis08(title03, title03 + N3, alloc01);
+ size02 = lis08.size();
+
+ lis07.swap(lis08);
+ VERIFY( lis07.size() == size02 );
+ VERIFY( equal(lis07.begin(), lis07.end(), title03) );
+ VERIFY( lis08.size() == size01 );
+ VERIFY( equal(lis08.begin(), lis08.end(), title01) );
+
+ list_type lis09(title03, title03 + N3, alloc01);
+ size01 = lis09.size();
+ list_type lis10(title04, title04 + N4, alloc01);
+ size02 = lis10.size();
+
+ lis09.swap(lis10);
+ VERIFY( lis09.size() == size02 );
+ VERIFY( equal(lis09.begin(), lis09.end(), title04) );
+ VERIFY( lis10.size() == size01 );
+ VERIFY( equal(lis10.begin(), lis10.end(), title03) );
+
+ list_type lis11(title04, title04 + N4, alloc01);
+ size01 = lis11.size();
+ list_type lis12(title01, title01 + N1, alloc01);
+ size02 = lis12.size();
+
+ lis11.swap(lis12);
+ VERIFY( lis11.size() == size02 );
+ VERIFY( equal(lis11.begin(), lis11.end(), title01) );
+ VERIFY( lis12.size() == size01 );
+ VERIFY( equal(lis12.begin(), lis12.end(), title04) );
+
+ list_type lis13(title03, title03 + N3, alloc01);
+ size01 = lis13.size();
+ list_type lis14(title03, title03 + N3, alloc01);
+ size02 = lis14.size();
+
+ lis13.swap(lis14);
+ VERIFY( lis13.size() == size02 );
+ VERIFY( equal(lis13.begin(), lis13.end(), title03) );
+ VERIFY( lis14.size() == size01 );
+ VERIFY( equal(lis14.begin(), lis14.end(), title03) );
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc
new file mode 100644
index 000000000..676466d53
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc
@@ -0,0 +1,31 @@
+// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <list>
+#include "3.h"
+
+int main()
+{
+ typedef char value_type;
+ typedef __gnu_test::uneq_allocator<value_type> allocator_type;
+ typedef std::list<value_type, allocator_type> list_type;
+
+ swap3<list_type>();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h
new file mode 100644
index 000000000..b4f2cd097
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h
@@ -0,0 +1,156 @@
+// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.2.3 list::swap
+
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+// uneq_allocator, two different personalities.
+template<typename _Tp>
+void
+swap3()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef _Tp list_type;
+ typedef typename list_type::allocator_type allocator_type;
+ typedef typename list_type::size_type size_type;
+
+ const char title01[] = "Rivers of sand";
+ const char title02[] = "Concret PH";
+ const char title03[] = "Sonatas and Interludes for Prepared Piano";
+ const char title04[] = "never as tired as when i'm waking up";
+
+ const size_t N1 = sizeof(title01);
+ const size_t N2 = sizeof(title02);
+ const size_t N3 = sizeof(title03);
+ const size_t N4 = sizeof(title04);
+
+ size_type size01, size02;
+
+ allocator_type alloc01(1), alloc02(2);
+ int personality01, personality02;
+
+ list_type lis01(alloc01);
+ size01 = lis01.size();
+ personality01 = lis01.get_allocator().get_personality();
+ list_type lis02(alloc02);
+ size02 = lis02.size();
+ personality02 = lis02.get_allocator().get_personality();
+
+ lis01.swap(lis02);
+ VERIFY( lis01.size() == size02 );
+ VERIFY( lis01.empty() );
+ VERIFY( lis02.size() == size01 );
+ VERIFY( lis02.empty() );
+ VERIFY( lis01.get_allocator().get_personality() == personality02 );
+ VERIFY( lis02.get_allocator().get_personality() == personality01 );
+
+ list_type lis03(alloc02);
+ size01 = lis03.size();
+ personality01 = lis03.get_allocator().get_personality();
+ list_type lis04(title02, title02 + N2, alloc01);
+ size02 = lis04.size();
+ personality02 = lis04.get_allocator().get_personality();
+
+ lis03.swap(lis04);
+ VERIFY( lis03.size() == size02 );
+ VERIFY( equal(lis03.begin(), lis03.end(), title02) );
+ VERIFY( lis04.size() == size01 );
+ VERIFY( lis04.empty() );
+ VERIFY( lis03.get_allocator().get_personality() == personality02 );
+ VERIFY( lis04.get_allocator().get_personality() == personality01 );
+
+ list_type lis05(title01, title01 + N1, alloc01);
+ size01 = lis05.size();
+ personality01 = lis05.get_allocator().get_personality();
+ list_type lis06(title02, title02 + N2, alloc02);
+ size02 = lis06.size();
+ personality02 = lis06.get_allocator().get_personality();
+
+ lis05.swap(lis06);
+ VERIFY( lis05.size() == size02 );
+ VERIFY( equal(lis05.begin(), lis05.end(), title02) );
+ VERIFY( lis06.size() == size01 );
+ VERIFY( equal(lis06.begin(), lis06.end(), title01) );
+ VERIFY( lis05.get_allocator().get_personality() == personality02 );
+ VERIFY( lis06.get_allocator().get_personality() == personality01 );
+
+ list_type lis07(title01, title01 + N1, alloc02);
+ size01 = lis07.size();
+ personality01 = lis07.get_allocator().get_personality();
+ list_type lis08(title03, title03 + N3, alloc01);
+ size02 = lis08.size();
+ personality02 = lis08.get_allocator().get_personality();
+
+ lis07.swap(lis08);
+ VERIFY( lis07.size() == size02 );
+ VERIFY( equal(lis07.begin(), lis07.end(), title03) );
+ VERIFY( lis08.size() == size01 );
+ VERIFY( equal(lis08.begin(), lis08.end(), title01) );
+ VERIFY( lis07.get_allocator().get_personality() == personality02 );
+ VERIFY( lis08.get_allocator().get_personality() == personality01 );
+
+ list_type lis09(title03, title03 + N3, alloc01);
+ size01 = lis09.size();
+ personality01 = lis09.get_allocator().get_personality();
+ list_type lis10(title04, title04 + N4, alloc02);
+ size02 = lis10.size();
+ personality02 = lis10.get_allocator().get_personality();
+
+ lis09.swap(lis10);
+ VERIFY( lis09.size() == size02 );
+ VERIFY( equal(lis09.begin(), lis09.end(), title04) );
+ VERIFY( lis10.size() == size01 );
+ VERIFY( equal(lis10.begin(), lis10.end(), title03) );
+ VERIFY( lis09.get_allocator().get_personality() == personality02 );
+ VERIFY( lis10.get_allocator().get_personality() == personality01 );
+
+ list_type lis11(title04, title04 + N4, alloc02);
+ size01 = lis11.size();
+ personality01 = lis11.get_allocator().get_personality();
+ list_type lis12(title01, title01 + N1, alloc01);
+ size02 = lis12.size();
+ personality02 = lis12.get_allocator().get_personality();
+
+ lis11.swap(lis12);
+ VERIFY( lis11.size() == size02 );
+ VERIFY( equal(lis11.begin(), lis11.end(), title01) );
+ VERIFY( lis12.size() == size01 );
+ VERIFY( equal(lis12.begin(), lis12.end(), title04) );
+ VERIFY( lis11.get_allocator().get_personality() == personality02 );
+ VERIFY( lis12.get_allocator().get_personality() == personality01 );
+
+ list_type lis13(title03, title03 + N3, alloc01);
+ size01 = lis13.size();
+ personality01 = lis13.get_allocator().get_personality();
+ list_type lis14(title03, title03 + N3, alloc02);
+ size02 = lis14.size();
+ personality02 = lis14.get_allocator().get_personality();
+
+ lis13.swap(lis14);
+ VERIFY( lis13.size() == size02 );
+ VERIFY( equal(lis13.begin(), lis13.end(), title03) );
+ VERIFY( lis14.size() == size01 );
+ VERIFY( equal(lis14.begin(), lis14.end(), title03) );
+ VERIFY( lis13.get_allocator().get_personality() == personality02 );
+ VERIFY( lis14.get_allocator().get_personality() == personality01 );
+}