diff options
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers')
695 files changed, 35966 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/array/range_access.cc b/libstdc++-v3/testsuite/23_containers/array/range_access.cc new file mode 100644 index 000000000..fb691d0d8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <array> + +void +test01() +{ + std::array<int, 3> a{{1, 2, 3}}; + std::begin(a); + std::end(a); +} diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/citerators.cc new file mode 100644 index 000000000..c448a8419 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <array> +#include <testsuite_containers.h> + +int main() +{ + typedef std::array<int, 7> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_functions.cc new file mode 100644 index 000000000..ef8c5aac7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_functions.cc @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 <array> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_functions + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr _Ttesttype a = { }; + constexpr auto v1 __attribute__((unused)) = a.size(); + constexpr auto v2 __attribute__((unused)) = a.max_size(); + constexpr auto v3 __attribute__((unused)) = a.empty(); + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_functions test; + test.operator()<std::array<long, 60>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..0e1044124 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/1.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <array> + +template class std::array<int, 5>; diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..aadf76b72 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/2.cc @@ -0,0 +1,27 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <array> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +template class std::array<__gnu_test::NonDefaultConstructible, 3>; diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..9bd5bc9c0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/explicit_instantiation/3.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <array> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// libstdc++/41792 +template class std::array<__gnu_test::OverloadedAddress, 3>; diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/fill.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/fill.cc new file mode 100644 index 000000000..5586b7062 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/fill.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-06-13 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 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 <array> +#include <testsuite_hooks.h> + +// DR 776. Undescribed assign function of std::array. +void test01() +{ + bool test __attribute__((unused)) = true; + + const size_t len = 3; + typedef std::array<int, len> array_type; + + array_type a = { { 0, 1, 2 } }; + const int value = 5; + + a.fill(value); + VERIFY( a[0] == value ); + VERIFY( a[1] == value ); + VERIFY( a[2] == value ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/typedefs.cc new file mode 100644 index 000000000..152988df7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <array> + +// Check container for required typedefs. +__gnu_test::types<std::array<int, 10> > t; diff --git a/libstdc++-v3/testsuite/23_containers/bitset/18604.cc b/libstdc++-v3/testsuite/23_containers/bitset/18604.cc new file mode 100644 index 000000000..f0c06aa62 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/18604.cc @@ -0,0 +1,42 @@ +// 2005-05-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include <bitset> diff --git a/libstdc++-v3/testsuite/23_containers/bitset/45713.cc b/libstdc++-v3/testsuite/23_containers/bitset/45713.cc new file mode 100644 index 000000000..8d369d63e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/45713.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2010 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/>. + +// { dg-do compile } + +#include <bitset> + +// libstdc++/45713 +#if __SIZEOF_SIZE_T__ >= 4 +int test[sizeof(std::bitset<0xffffffff>) != 1 ? 1 : -1]; +#endif diff --git a/libstdc++-v3/testsuite/23_containers/bitset/all/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/all/1.cc new file mode 100644 index 000000000..c23c1e96f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/all/1.cc @@ -0,0 +1,80 @@ +// 2007-11-23 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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.3.5.2 bitset members + +#include <bitset> +#include <testsuite_hooks.h> + +// DR 693. std::bitset::all() missing. +void test01() +{ + bool test __attribute__((unused)) = true; + + std::bitset<0> z1; + VERIFY( z1.all() ); + z1.set(); + VERIFY( z1.all() ); + + std::bitset<8> z2; + VERIFY( !z2.all() ); + z2.set(); + VERIFY( z2.all() ); + + std::bitset<16> z3; + VERIFY( !z3.all() ); + z3.set(); + VERIFY( z3.all() ); + + std::bitset<32> z4; + VERIFY( !z4.all() ); + z4.set(); + VERIFY( z4.all() ); + + std::bitset<64> z5; + VERIFY( !z5.all() ); + z5.set(); + VERIFY( z5.all() ); + + std::bitset<96> z6; + VERIFY( !z6.all() ); + z6.set(); + VERIFY( z6.all() ); + + std::bitset<128> z7; + VERIFY( !z7.all() ); + z7.set(); + VERIFY( z7.all() ); + + std::bitset<192> z8; + VERIFY( !z8.all() ); + z8.set(); + VERIFY( z8.all() ); + + std::bitset<1024> z9; + VERIFY( !z9.all() ); + z9.set(); + VERIFY( z9.all() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/1.cc new file mode 100644 index 000000000..cc391c419 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/1.cc @@ -0,0 +1,84 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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.3.5.1 bitset constructors + +#include <string> +#include <bitset> +#include <algorithm> // std::reverse +#include <stdexcept> +#include <testsuite_hooks.h> + +bool test01(void) +{ + bool test __attribute__((unused)) = true; + + // bitset() + const size_t n1 = 5; + std::bitset<n1> bit01; + for (size_t i = 0; i < n1; ++i) + VERIFY( !bit01.test(i) ); + + // bitset(unsigned long) + const size_t n2 = 32; + unsigned long ul1 = 2; + std::bitset<n2> bit02(ul1); + VERIFY( !bit02.test(0) ); + VERIFY( bit02.test(1) ); + VERIFY( !bit02.test(2) ); + + // template<_CharT, _Traits, _Alloc> + // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n) + std::string str01("stuff smith sessions"); + const size_t n3 = 128; + try { + std::bitset<n3> bit03(str01, 5); + } + catch(std::invalid_argument& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + std::string str02("010101000011"); + int sz = str02.size(); + try { + std::bitset<n3> bit03(str02, 0); + std::string str03; + for (int i = 0; i < sz; ++i) + str03 += (bit03.test(i) ? '1' : '0'); + std::reverse(str03.begin(), str03.end()); + VERIFY( str03 == str02 ); + } + catch(std::invalid_argument& fail) { + VERIFY( false ); + } + catch(...) { + VERIFY( false ); + } + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/16020.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/16020.cc new file mode 100644 index 000000000..f30746161 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/16020.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2004, 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 <debug/bitset> +#include <testsuite_hooks.h> + +// libstdc++/16020 +void test01() +{ + using __gnu_debug::bitset; + bool test __attribute__((unused)) = true; + + bitset<5> b(7); + bitset<5> c; + + bitset<5> bb(b); + c = bb; + + VERIFY( bb == b ); + VERIFY( c == bb ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/2.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/2.cc new file mode 100644 index 000000000..4a394473f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/2.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2009, 2010 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 <bitset> +#include <string> +#include <testsuite_hooks.h> + +struct X +{ + operator const char*() { return "10101010"; } +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + X x; + std::string s(x); + std::bitset<32> b1(static_cast<const char*>(x)); + std::bitset<32> b2(s); + VERIFY( b1 == b2 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/3.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/3.cc new file mode 100644 index 000000000..b90806870 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/3.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-31 Paolo Carlini <paolo.carlini@oracle.com> + +// 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 <bitset> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + const unsigned long long num0 = 0ULL; + std::bitset<0> bs0(num0); + VERIFY( bs0.to_ullong() == num0 ); + + const unsigned long long num1 = 215ULL; + std::bitset<32> bs1(num1); + VERIFY( bs1.to_ullong() == num1 ); + + const unsigned long long num2 = 215ULL; + std::bitset<64> bs2(num2); + VERIFY( bs2.to_ullong() == num2 ); + + const unsigned long long num3 = 343353215ULL; + std::bitset<32> bs3(num3); + VERIFY( bs3.to_ullong() == num3 ); + + const unsigned long long num4 = 343353215ULL; + std::bitset<64> bs4(num4); + VERIFY( bs4.to_ullong() == num4 ); + + const unsigned long long num5 = 13008719539498589283ULL; + std::bitset<64> bs5(num5); + VERIFY( bs5.to_ullong() == num5 ); + + const unsigned long long num6 = 13008719539498589283ULL; + std::bitset<128> bs6(num6); + VERIFY( bs6.to_ullong() == num6 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/38244.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/38244.cc new file mode 100644 index 000000000..fae2174b0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/38244.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2008, 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/>. + +// { dg-do compile } + +#include <bitset> + +class C0 +{ + public: + C0() : b(0) { } + private: + std::bitset<1> b; +}; + +class C1 +{ + public: + C1() : b(1) { } + private: + std::bitset<1> b; +}; + +// libstdc++/38244 +void func() +{ + C0 val0; + C1 val1; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/50268.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/50268.cc new file mode 100644 index 000000000..6a61d7e2f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/50268.cc @@ -0,0 +1,84 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011 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 <bitset> +#include <testsuite_hooks.h> + +// libstdc++/50268 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::bitset<1> b1(3ULL); + VERIFY( b1.count() == 1ULL ); + + std::bitset<3> b2(30ULL); + VERIFY( b2.count() == 2ULL ); + + std::bitset<6> b3(300ULL); + VERIFY( b3.count() == 3ULL ); + + std::bitset<9> b4(3000ULL); + VERIFY( b4.count() == 5ULL ); + + std::bitset<16> b5(300000ULL); + VERIFY( b5.count() == 7ULL ); + + std::bitset<24> b6(30000000ULL); + VERIFY( b6.count() == 9ULL ); + + std::bitset<32> b7(30000000000ULL); + VERIFY( b7.count() == 13ULL ); + + std::bitset<37> b8(3000000000000ULL); + VERIFY( b8.count() == 18ULL ); + + std::bitset<40> b9(30000000000000ULL); + VERIFY( b9.count() == 16ULL ); + + std::bitset<45> b10(30000000000000ULL); + VERIFY( b10.count() == 20ULL ); + + std::bitset<64> b11(30000000000000ULL); + VERIFY( b11.count() == 20ULL ); + + std::bitset<100> b12(30000000000000ULL); + VERIFY( b12.count() == 20ULL ); + + std::bitset<200> b13(30000000000000ULL); + VERIFY( b13.count() == 20ULL ); + + std::bitset<45> b14(18446744073709551615ULL); + VERIFY( b14.count() == 45ULL ); + + std::bitset<64> b15(18446744073709551615ULL); + VERIFY( b15.count() == 64ULL ); + + std::bitset<100> b16(18446744073709551615ULL); + VERIFY( b16.count() == 64ULL ); + + std::bitset<200> b17(18446744073709551615ULL); + VERIFY( b17.count() == 64ULL ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/6282.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/6282.cc new file mode 100644 index 000000000..387852412 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/6282.cc @@ -0,0 +1,63 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 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.3.5.1 bitset constructors + +#include <string> +#include <bitset> +#include <stdexcept> +#include <testsuite_hooks.h> + +// boundary condition: a zero-sized set +// libstdc++/6282 +bool test02(void) +{ + using std::char_traits; using std::allocator; + bool test __attribute__((unused)) = true; + + std::bitset<0> z1; + VERIFY( z1.any() == false ); + + std::bitset<0> z2(12345); + VERIFY( z2.any() == false ); + + std::bitset<0> z3(std::string("10101010101")); + VERIFY( z3.any() == false ); + + try { + z1.set(0); + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + + VERIFY( z1.to_ulong() == 0 ); + VERIFY( (z1.to_string<char,char_traits<char>,allocator<char> >().empty() )); + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/constexpr.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/constexpr.cc new file mode 100644 index 000000000..aea503013 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/constexpr.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 <bitset> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_default_constructible test1; + test1.operator()<std::bitset<0>>(); + test1.operator()<std::bitset<1>>(); + test1.operator()<std::bitset<256>>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator()<std::bitset<0>, unsigned long long>(); + test2.operator()<std::bitset<1>, unsigned long long>(); + test2.operator()<std::bitset<256>, unsigned long long>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-1.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-1.cc new file mode 100644 index 000000000..c79727e04 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-1.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-10-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <bitset> + +// DR 1325. +std::bitset<10> b(0); diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc new file mode 100644 index 000000000..e261ce5e6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <bitset> +#include <testsuite_hooks.h> + +template<std::size_t Nb, typename CharT> + std::bitset<Nb> + test01_ref(const CharT* str, + typename std::basic_string<CharT>::size_type n + = std::basic_string<CharT>::npos, + CharT zero = CharT('0'), CharT one = CharT('1')) + { + return std::bitset<Nb>(n == std::basic_string<CharT>::npos + ? std::basic_string<CharT>(str) + : std::basic_string<CharT>(str, n), + 0, n, zero, one); + } + +// DR 1325. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const char s1[4] = { '0', '1', '0', '1' }; + VERIFY( bitset<4>(s1, 4) == test01_ref<4>(s1, 4) ); + + const char s2[3] = { '1', '1', '0' }; + VERIFY( bitset<6>(s2, 3) == test01_ref<6>(s2, 3) ); + + const char* s3 = "1110110"; + VERIFY( bitset<7>(s3) == test01_ref<7>(s3) ); + + const char* s4 = "0011"; + VERIFY( bitset<10>(s4) == test01_ref<10>(s4) ); + + const char* s5 = "011110000111001"; + VERIFY( bitset<5>(s5) == test01_ref<5>(s5) ); + + const char* s6 = "1cc1c1"; + VERIFY( bitset<6>(s6, basic_string<char>::npos, 'c') + == test01_ref<6>(s6, basic_string<char>::npos, 'c') ); + + const char* s7 = "001011101"; + VERIFY( bitset<9>(s7, basic_string<char>::npos, '0', '1') + == test01_ref<9>(s7, basic_string<char>::npos, '0', '1') ); + + const char* s8 = "babb"; + VERIFY( bitset<4>(s8, basic_string<char>::npos, 'a', 'b') + == test01_ref<4>(s8, basic_string<char>::npos, 'a', 'b') ); + + const char* s9 = "bbabbbaaa"; + VERIFY( bitset<100>(s9, basic_string<char>::npos, 'a', 'b') + == test01_ref<100>(s9, basic_string<char>::npos, 'a', 'b') ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/cons/dr396.cc b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr396.cc new file mode 100644 index 000000000..9fdb807d8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/cons/dr396.cc @@ -0,0 +1,51 @@ +// 2009-09-23 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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 <bitset> +#include <testsuite_hooks.h> + +// DR 396. what are characters zero and one. +void test01() +{ + bool test __attribute__((unused)) = true; + + std::bitset<4> z1(std::string("bbab"), 0, std::string::npos, 'a', 'b'); + VERIFY( z1.to_string('a', 'b') == "bbab" ); + + std::bitset<4> z2(std::string("11a1"), 0, std::string::npos, 'a'); + VERIFY( z2.to_string('a') == "11a1" ); + + std::bitset<8> z3(std::string("babb"), 0, std::string::npos, 'a', 'b'); + VERIFY( z3.to_string('a', 'b') == "aaaababb" ); + + std::bitset<8> z4(std::string("1a11"), 0, std::string::npos, 'a'); + VERIFY( z4.to_string('a') == "aaaa1a11" ); + + std::bitset<2> z5(std::string("bbab"), 0, std::string::npos, 'a', 'b'); + VERIFY( z5.to_string('a', 'b') == "bb" ); + + std::bitset<2> z6(std::string("11a1"), 0, std::string::npos, 'a'); + VERIFY( z6.to_string('a') == "11" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/count/6124.cc b/libstdc++-v3/testsuite/23_containers/bitset/count/6124.cc new file mode 100644 index 000000000..81061541e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/count/6124.cc @@ -0,0 +1,38 @@ +// 2001-06-03 pme + +// Copyright (C) 2001, 2002, 2003, 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.3.5.2 bitset members + +#include <bitset> +#include <stdexcept> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/6124 +void test02() +{ + std::bitset<1> bs; + bs.count(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/debug/invalidation/1.cc new file mode 100644 index 000000000..5959d5fff --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/debug/invalidation/1.cc @@ -0,0 +1,47 @@ +// Bitset reference invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/bitset> +#include <testsuite_hooks.h> + +using __gnu_debug::bitset; + +bool test = true; + +// Disappear +void test01() +{ + bitset<32>::reference* i; + { + bitset<32> bs; + bs.flip(7); + i = new bitset<32>::reference(bs[7]); + VERIFY(*i); + } +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + VERIFY(i->_M_singular()); +#endif + delete i; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/ext/15361.cc b/libstdc++-v3/testsuite/23_containers/bitset/ext/15361.cc new file mode 100644 index 000000000..574f5d7d4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/ext/15361.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2004, 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 <bitset> +#include <testsuite_hooks.h> + +// libstdc++/15361 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + bitset<256> b; + b.set(225); + b.set(226); + + VERIFY( b._Find_first() == 225 ); + VERIFY( b._Find_next(225) == 226 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc new file mode 100644 index 000000000..655192e4e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 <bitset> + +void test01() +{ + std::bitset<0> b0; + std::hash<std::bitset<0>> h0; + h0(b0); + + std::bitset<10> b1; + std::hash<std::bitset<10>> h1; + h1(b1); + + std::bitset<100> b2; + std::hash<std::bitset<100>> h2; + h2(b2); + + std::bitset<1000> b3; + std::hash<std::bitset<1000>> h3; + h3(b3); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/input/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/input/1.cc new file mode 100644 index 000000000..bf441e00d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/input/1.cc @@ -0,0 +1,49 @@ +// 2003-12-03 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2003, 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.3.5.3 bitset operators + +#include <bitset> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + bitset<5> b5; + bitset<0> b0; + stringstream ss; + + ss.str("*"); + ss >> b5; + VERIFY( ss.rdstate() == ios_base::failbit ); + + ss.clear(); + ss.str("*"); + ss >> b0; + VERIFY( ss.rdstate() == ios_base::goodbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/operations/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/operations/1.cc new file mode 100644 index 000000000..227b66429 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/operations/1.cc @@ -0,0 +1,108 @@ +// 2000-01-15 Anders Widell <awl@hem.passagen.se> + +// Copyright (C) 2000, 2003, 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 <string> +#include <set> +#include <bitset> +#include <testsuite_hooks.h> + +static char original_bits[1024]; +static char left_shifted[1024]; +static char right_shifted[1024]; + +char +random_bit() { + static long x = 1; + return ((x = (3432L*x + 6789L) % 9973L) & 1) + '0'; +} + +void +initialise(size_t size) { + for (size_t i=0; i<size; i++) + original_bits[i] = random_bit(); + + original_bits[size] = '\0'; + left_shifted[size] = '\0'; + right_shifted[size] = '\0'; +} + +void +shift_arrays(size_t shift_step, size_t size) { + for (size_t i=shift_step; i<size; i++) { + right_shifted[i] = original_bits[i-shift_step]; + left_shifted[size-i-1] = original_bits[size+shift_step-i-1]; + } + for (size_t i=0; i<shift_step && i<size; i++) { + right_shifted[i] = '0'; + left_shifted[size-i-1] = '0'; + } +} + +template <size_t size> + bool + do_test() { + bool test __attribute__((unused)) = true; + + std::bitset<size> shifted; + std::bitset<size> correct; + + initialise(size); + + //std::bitset<size> original = std::string(original_bits); + std::bitset<size> original = std::bitset<size> (std::string(original_bits)); + + for (size_t shift_step=0; shift_step==0 || shift_step<size; shift_step++) { + shift_arrays(shift_step, size); + + shifted = original; + shifted <<= shift_step; + //correct = std::string(left_shifted); + correct = std::bitset<size> (std::string(left_shifted)); + VERIFY( shifted == correct ); + + shifted = original; + shifted >>= shift_step; + //correct = std::string(right_shifted); + correct = std::bitset<size> (std::string(right_shifted)); + VERIFY( shifted == correct ); + } + + return test; + } + +bool +test01() { + bool test __attribute__((unused)) = true; + + VERIFY( do_test<32>() ); + VERIFY( do_test<48>() ); + VERIFY( do_test<64>() ); + + VERIFY( do_test<511>() ); + VERIFY( do_test<513>() ); + VERIFY( do_test<997>() ); + return test; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/operations/13838.cc b/libstdc++-v3/testsuite/23_containers/bitset/operations/13838.cc new file mode 100644 index 000000000..f47fa6e88 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/operations/13838.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2004, 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 <debug/bitset> +#include <testsuite_hooks.h> + +// libstdc++/13838 +void test01() +{ + using __gnu_debug::bitset; + bool test __attribute__((unused)) = true; + + bitset<4> b0, b1; + b0.set(1); + b0.set(3); + b1.set(2); + b1.set(3); + + b0 |= b1; + + bitset<4> br; + br.set(1); + br.set(2); + br.set(3); + + VERIFY( b0 == br ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/operations/2.cc b/libstdc++-v3/testsuite/23_containers/bitset/operations/2.cc new file mode 100644 index 000000000..f234b2b10 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/operations/2.cc @@ -0,0 +1,41 @@ +// 2000-01-15 Anders Widell <awl@hem.passagen.se> + +// Copyright (C) 2000, 2003, 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 <string> +#include <set> +#include <bitset> +#include <testsuite_hooks.h> + +bool +test02() +{ + bool test __attribute__((unused)) = true; + + std::bitset<66> b; + b <<= 400; + VERIFY( b.count() == 0 ); + return test; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/requirements/constexpr_functions.cc b/libstdc++-v3/testsuite/23_containers/bitset/requirements/constexpr_functions.cc new file mode 100644 index 000000000..d5b8b478c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/requirements/constexpr_functions.cc @@ -0,0 +1,55 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 <bitset> +#include <testsuite_common_types.h> + +namespace __gnu_test +{ + struct constexpr_member_functions + { + template<typename _Ttesttype> + void + operator()() + { + struct _Concept + { + void __constraint() + { + constexpr _Ttesttype obj; + constexpr auto v1 __attribute__((unused)) = obj.size(); + // constexpr auto v2 = obj[4]; + } + }; + + _Concept c; + c.__constraint(); + } + }; +} + +int main() +{ + __gnu_test::constexpr_member_functions test; + test.operator()<std::bitset<0>>(); + test.operator()<std::bitset<1>>(); + test.operator()<std::bitset<64>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..25bfef8d1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <bitset> + +template class std::bitset<10>; diff --git a/libstdc++-v3/testsuite/23_containers/bitset/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/bitset/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..0393ac71d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers. + +#include <bitset> + +template class std::bitset<10>; diff --git a/libstdc++-v3/testsuite/23_containers/bitset/test/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/test/1.cc new file mode 100644 index 000000000..7f654d83f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/test/1.cc @@ -0,0 +1,52 @@ +// 2001-06-03 pme + +// Copyright (C) 2001, 2002, 2003, 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.3.5.2 bitset members + +#include <bitset> +#include <stdexcept> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01(void) +{ + bool test __attribute__((unused)) = true; + const size_t n1 = 5; + + // the other 22 member functions should be in here too... + try { + std::bitset<n1> five_bits; + bool unused __attribute__((unused)) = five_bits.test(n1); // should throw + VERIFY( false ); + } + catch(std::out_of_range& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc new file mode 100644 index 000000000..a6e77b7aa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc @@ -0,0 +1,52 @@ +// 2004-11-17 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 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.3.5.2 bitset members + +#include <bitset> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + bitset<5> b5; + string s0 = b5.to_string<char, char_traits<char>, allocator<char> >(); + VERIFY( s0 == "00000" ); + + // DR 434. bitset::to_string() hard to use. + b5.set(0); + string s1 = b5.to_string<char, char_traits<char> >(); + VERIFY( s1 == "00001" ); + + b5.set(2); + string s2 = b5.to_string<char>(); + VERIFY( s2 == "00101" ); + + b5.set(4); + string s3 = b5.to_string(); + VERIFY( s3 == "10101" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/to_string/dr396.cc b/libstdc++-v3/testsuite/23_containers/bitset/to_string/dr396.cc new file mode 100644 index 000000000..d16f43561 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/to_string/dr396.cc @@ -0,0 +1,64 @@ +// 2008-09-23 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2008, 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.3.5.2 bitset members + +#include <bitset> +#include <testsuite_hooks.h> + +// DR 396. what are characters zero and one. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + bitset<5> b5; + string s0 = b5.to_string<char, char_traits<char>, allocator<char> >('a', 'b'); + VERIFY( s0 == "aaaaa" ); + + string s1 = b5.to_string<char, char_traits<char>, allocator<char> >('b'); + VERIFY( s1 == "bbbbb" ); + + b5.set(0); + string s2 = b5.to_string<char, char_traits<char> >('c', 'd'); + VERIFY( s2 == "ccccd" ); + + string s3 = b5.to_string<char, char_traits<char> >('d'); + VERIFY( s3 == "dddd1" ); + + b5.set(2); + string s4 = b5.to_string<char>('e', 'f'); + VERIFY( s4 == "eefef" ); + + string s5 = b5.to_string<char>('f'); + VERIFY( s5 == "ff1f1" ); + + b5.set(4); + string s6 = b5.to_string('g', 'h'); + VERIFY( s6 == "hghgh" ); + + string s7 = b5.to_string('h'); + VERIFY( s7 == "1h1h1" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/to_ullong/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/to_ullong/1.cc new file mode 100644 index 000000000..2a3b886c3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/to_ullong/1.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-29 Paolo Carlini <paolo.carlini@oracle.com> + +// 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 <bitset> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::bitset<0> bs0; + VERIFY( bs0.to_ullong() == 0 ); + + std::bitset<64> bs1("11010111"); + VERIFY( bs1.to_ullong() == 215 ); + + std::bitset<64> bs2("10110100100010000100000101111111" + "01111110011111110001110001100011"); + VERIFY( bs2.to_ullong() == 13008719539498589283ULL ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset/to_ulong/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/to_ulong/1.cc new file mode 100644 index 000000000..8b4de2ced --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/to_ulong/1.cc @@ -0,0 +1,47 @@ +// 2001-06-03 pme + +// Copyright (C) 2001, 2002, 2003, 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.3.5.2 bitset members + +#include <bitset> +#include <stdexcept> +#include <sstream> +#include <testsuite_hooks.h> + +void test03() +{ + bool test __attribute__((unused)) = true; + std::bitset<5> b; + std::stringstream ss("101"); + ss.exceptions(std::ios_base::eofbit); + + try + { + ss >> b; + } + catch (std::exception&) { } + + VERIFY( b.to_ulong() == 5 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/14340.cc b/libstdc++-v3/testsuite/23_containers/deque/14340.cc new file mode 100644 index 000000000..b3f7ca5dc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/14340.cc @@ -0,0 +1,35 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <deque> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::deque<int> container; + __gnu_test::conversion<container>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/18604.cc b/libstdc++-v3/testsuite/23_containers/deque/18604.cc new file mode 100644 index 000000000..69e49e085 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/18604.cc @@ -0,0 +1,42 @@ +// 2005-05-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include <deque> diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/29134-2.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/29134-2.cc new file mode 100644 index 000000000..c5d70dcf7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/29134-2.cc @@ -0,0 +1,50 @@ +// Copyright (C) 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.1.2 deque capacity [lib.deque.capacity] + +#include <deque> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + deque<int> d; + + try + { + d.resize(size_t(-1)); + } + catch(const std::length_error&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/29134.cc new file mode 100644 index 000000000..23d4dfc70 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/29134.cc @@ -0,0 +1,37 @@ +// Copyright (C) 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.1.2 deque capacity [lib.deque.capacity] + +#include <deque> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<int> d; + + VERIFY( d.max_size() == d.get_allocator().max_size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc new file mode 100644 index 000000000..475880888 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/moveable.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2009, 2010 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 <deque> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<copycounter> a; + copycounter::copycount = 0; + a.resize(10); + a.resize(98); + a.resize(99); + a.resize(100); + VERIFY( copycounter::copycount == 0 ); + + a.resize(99); + a.resize(0); + VERIFY( copycounter::copycount == 0 ); + + a.resize(100); + VERIFY( copycounter::copycount == 0 ); + + a.clear(); + VERIFY( copycounter::copycount == 0 ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc new file mode 100644 index 000000000..229a0eb60 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <deque> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<__gnu_test::NonCopyConstructible> d; + VERIFY( std::distance(d.begin(), d.end()) == 0 ); + + d.resize(1000); + VERIFY( std::distance(d.begin(), d.end()) == 1000 ); + for(auto it = d.begin(); it != d.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/shrink_to_fit.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/shrink_to_fit.cc new file mode 100644 index 000000000..4cd556456 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/shrink_to_fit.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <vector> +#include <testsuite_hooks.h> + +// libstdc++/42573 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> d(100); + d.push_back(1); + d.push_back(1); + // VERIFY( d.size() < d.capacity() ); + d.shrink_to_fit(); + // VERIFY( d.size() == d.capacity() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/check_construct_destroy.cc b/libstdc++-v3/testsuite/23_containers/deque/check_construct_destroy.cc new file mode 100644 index 000000000..23e319dfe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/check_construct_destroy.cc @@ -0,0 +1,73 @@ +// 2004-07-26 Matt Austern <austern@apple.com> +// +// Copyright (C) 2003, 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 <deque> +#include <testsuite_allocator.h> + +using namespace __gnu_test; + +int main() +{ + typedef std::deque<int, tracker_allocator<int> > Container; + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + Container c; + ok = check_construct_destroy("empty container", 0, 0) && ok; + } + ok = check_construct_destroy("empty container", 0, 0) && ok; + + + tracker_allocator_counter::reset(); + { + Container c(arr10, arr10 + 10); + ok = check_construct_destroy("Construct from range", 10, 0) && ok; + } + ok = check_construct_destroy("Construct from range", 10, 10) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(c.begin(), arr10[0]); + ok = check_construct_destroy("Insert element", 1, 0) && ok; + } + ok = check_construct_destroy("Insert element", 1, 11) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(c.begin() + 5, arr10, arr10+3); + ok = check_construct_destroy("Insert short range", 3, 0) && ok; + } + ok = check_construct_destroy("Insert short range", 3, 13) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(c.begin() + 7, arr10, arr10+10); + ok = check_construct_destroy("Insert long range", 10, 0) && ok; + } + ok = check_construct_destroy("Insert long range", 10, 20) && ok; + + return ok ? 0 : 1;; +} + diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc new file mode 100644 index 000000000..579521582 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc @@ -0,0 +1,50 @@ +// 2001-12-27 pme +// +// Copyright (C) 2001, 2002, 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.1.1 deque constructors, copy, and assignment + +#include <deque> +#include <iterator> +#include <sstream> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +typedef std::deque<__gnu_test::object_counter> gdeque; + +bool test __attribute__((unused)) = true; + +// see http://gcc.gnu.org/ml/libstdc++/2001-11/msg00139.html +void +test01() +{ + assert_count (0); + { + gdeque d(10); + assert_count (10); + } + assert_count (0); +} + +int main() +{ + // specific bug fix checks + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc new file mode 100644 index 000000000..4df44f8eb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc @@ -0,0 +1,522 @@ +// 2001-12-27 pme +// +// Copyright (C) 2001, 2002, 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.1.1 deque constructors, copy, and assignment + +#include <deque> +#include <iterator> +#include <sstream> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +using __gnu_test::copy_tracker; +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; +using __gnu_test::copy_constructor; +using __gnu_test::assignment_operator; +using __gnu_test::object_counter; +using __gnu_test::destructor; + +typedef std::deque<object_counter> gdeque; + +bool test __attribute__((unused)) = true; + +// 23.2.1 required types +// +// A missing required type will cause a compile failure. +// +void +requiredTypesCheck() +{ + typedef int T; + typedef std::deque<T> X; + + typedef X::reference reference; + typedef X::const_reference const_reference; + typedef X::iterator iterator; + typedef X::const_iterator const_iterator; + typedef X::size_type size_type; + typedef X::difference_type difference_type; + typedef X::value_type value_type; + typedef X::allocator_type allocator_type; + typedef X::pointer pointer; + typedef X::const_pointer const_pointer; + typedef X::reverse_iterator reverse_iterator; + typedef X::const_reverse_iterator const_reverse_iterator; +} + + +// @fn defaultConstructorCheck +// Explicitly checks the default deque constructor and destructor for both +// trivial and non-trivial types. In addition, the size() and empty() +// member functions are explicitly checked here since it should be their +// first use. Checking those functions means checking the begin() and +// end() and their const brethren functions as well. +// +// @verbatim +// 23.2.1.1 default ctor/dtor +// effects: +// 23.2.1.1 constructs an empty deque using the specified allocator +// postconditions: +// 23.1 table 65 u.size() == 0 +// throws: +// complexity: +// 23.1 table 65 constant +// +// 23.2.1.2 bool empty() const +// semantics: +// 23.1 table 65 a.size() == 0 +// 23.1 (7) a.begin() == a.end() +// throws: +// complexity: +// 23.1 table 65 constant +// +// 23.2.1.2 size_type size() const +// semantics: +// 23.1 table 65 a.end() - a.begin() +// throws: +// complexity: +// 23.1 table 65(A) should be constant +// +// 23.2.1 iterator begin() +// const_iterator begin() const +// iterator end() +// const_iterator end() const +// throws: +// 23.1 (10) pt. 4 does not throw +// complexity: +// 23.1 table 65 constant +// @endverbatim +void +defaultConstructorCheckPOD() +{ + // setup + typedef int T; + typedef std::deque<T> X; + + // run test + X u; + + // assert postconditions + VERIFY(u.empty()); + VERIFY(0 == u.size()); + VERIFY(u.begin() == u.end()); + VERIFY(0 == std::distance(u.begin(), u.end())); + + // teardown +} + + +void +defaultConstructorCheck() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T> X; + + copy_tracker::reset(); + + // run test + const X u; + + // assert postconditions + VERIFY(u.empty()); + VERIFY(0 == u.size()); + VERIFY(u.begin() == u.end()); + VERIFY(0 == std::distance(u.begin(), u.end())); + + // teardown +} + + +// @fn copyConstructorCheck() +// Explicitly checks the deque copy constructor. Continues verificaton of +// ancillary member functions documented under defaultConstructorCheck(). +// +// This check also tests the push_back() member function. +// +// @verbatim +// 23.2.1 copy constructor +// effects: +// postconditions: +// 22.1.1 table 65 a == X(a) +// u == a +// throws: +// complexity: +// 22.1.1 table 65 linear +// @endverbatim +void +copyConstructorCheck() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T> X; + + const std::size_t copyBaseSize = 17; // arbitrary + + X a; + for (std::size_t i = 0; i < copyBaseSize; ++i) + a.push_back(i); + copy_tracker::reset(); + + // assert preconditions + VERIFY(!a.empty()); + VERIFY(copyBaseSize == a.size()); + VERIFY(a.begin() != a.end()); + VERIFY( copyBaseSize == static_cast<std::size_t>(std::distance(a.begin(), a.end())) ); + + // run test + X u = a; + + // assert postconditions + VERIFY(u == a); + VERIFY(copyBaseSize == copy_constructor::count()); + + // teardown +} + + +// @fn fillConstructorCheck() +// This test explicitly verifies the basic fill constructor. Like the default +// constructor, later tests depend on the fill constructor working correctly. +// That means this explicit test should preceed the later tests so the error +// message given on assertion failure can be more helpful n tracking the +// problem. +// +// 23.2.1.1 fill constructor +// complexity: +// 23.2.1.1 linear in N +void +fillConstructorCheck() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T> X; + + const X::size_type n(23); + const X::value_type t(111); + + copy_tracker::reset(); + + // run test + X a(n, t); + + // assert postconditions + VERIFY(n == a.size()); + VERIFY(n == copy_constructor::count()); + + // teardown +} + + +// @fn fillConstructorCheck2() +// Explicit check for fill constructors masqueraded as range constructors as +// elucidated in clause 23.1.1 paragraph 9 of the standard. +// +// 23.1.1 (9) fill constructor looking like a range constructor +void +fillConstructorCheck2() +{ + typedef copy_tracker T; + typedef std::deque<T> X; + + const std::size_t f = 23; + const std::size_t l = 111; + + copy_tracker::reset(); + + X a(f, l); + + VERIFY(f == a.size()); + VERIFY(f == copy_constructor::count()); +} + + +// @fn rangeConstructorCheckForwardIterator() +// This test copies from one deque to another to force the copy +// constructor for T to be used because the compiler will kindly +// elide copies if the default constructor can be used with +// type conversions. Trust me. +// +// 23.2.1.1 range constructor, forward iterators +void +rangeConstructorCheckForwardIterator() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T> X; + + const X::size_type n(726); + const X::value_type t(307); + X source(n, t); + X::iterator i = source.begin(); + X::iterator j = source.end(); + X::size_type rangeSize = std::distance(i, j); + + copy_tracker::reset(); + + // test + X a(i, j); + + // assert postconditions + VERIFY(rangeSize == a.size()); + VERIFY(copy_constructor::count() <= rangeSize); +} + + +// @fn rangeConstructorCheckInputIterator() +// An explicit check for range construction on an input iterator +// range, which the standard expounds upon as having a different +// complexity than forward iterators. +// +// 23.2.1.1 range constructor, input iterators +void +rangeConstructorCheckInputIterator() +{ + typedef copy_tracker T; + typedef std::deque<T> X; + + std::istringstream ibuf("1234567890123456789"); + const X::size_type rangeSize = ibuf.str().size(); + std::istream_iterator<char> i(ibuf); + std::istream_iterator<char> j; + + copy_tracker::reset(); + + X a(i, j); + + VERIFY(rangeSize == a.size()); + VERIFY(copy_constructor::count() <= (2 * rangeSize)); +} + + +// 23.2.1 copy assignment +void +copyAssignmentCheck() +{ + typedef copy_tracker T; + typedef std::deque<T> X; + + const X::size_type n(18); + const X::value_type t(1023); + X a(n, t); + X r; + + copy_tracker::reset(); + + r = a; + + VERIFY(r == a); + VERIFY(n == copy_constructor::count()); +} + + +// 23.2.1.1 fill assignment +// +// The complexity check must check dtors+copyAssign and +// copyCtor+copyAssign because that's the way the SGI implementation +// works. Dunno if it's true standard compliant (which specifies fill +// assignment in terms of erase and insert only), but it should work +// as (most) users expect and is more efficient. +void +fillAssignmentCheck() +{ + typedef copy_tracker T; + typedef std::deque<T> X; + + const X::size_type starting_size(10); + const X::value_type starting_value(66); + const X::size_type n(23); + const X::value_type t(111); + + X a(starting_size, starting_value); + copy_tracker::reset(); + + // preconditions + VERIFY(starting_size == a.size()); + + // test + a.assign(n, t); + + // postconditions + VERIFY(n == a.size()); + VERIFY(n == (copy_constructor::count() + assignment_operator::count())); + VERIFY(starting_size == (destructor::count() + assignment_operator::count())); +} + + +// @verbatim +// 23.2.1 range assignment +// 23.2.1.1 deque constructors, copy, and assignment +// effects: +// Constructs a deque equal to the range [first, last), using the +// specified allocator. +// +// template<typename InputIterator> +// assign(InputIterator first, InputIterator last); +// +// is equivalent to +// +// erase(begin(), end()); +// insert(begin(), first, last); +// +// postconditions: +// throws: +// complexity: +// forward iterators: N calls to the copy constructor, 0 reallocations +// input iterators: 2N calls to the copy constructor, log(N) reallocations +// @endverbatim +void +rangeAssignmentCheck() +{ + typedef copy_tracker T; + typedef std::deque<T> X; + + const X::size_type source_size(726); + const X::value_type source_value(307); + const X::size_type starting_size(10); + const X::value_type starting_value(66); + + X source(source_size, source_value); + X::iterator i = source.begin(); + X::iterator j = source.end(); + X::size_type rangeSize = std::distance(i, j); + + X a(starting_size, starting_value); + VERIFY(starting_size == a.size()); + + copy_tracker::reset(); + + a.assign(i, j); + + VERIFY(source == a); + VERIFY(rangeSize == (copy_constructor::count() + assignment_operator::count())); + VERIFY(starting_size == (destructor::count() + assignment_operator::count())); +} + + +// 23.1 (10) range assignment +// 23.2.1.3 with exception +void +rangeAssignmentCheckWithException() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T> X; + + // test + // What does "no effects" mean? +} + + +// 23.1.1 (9) fill assignment looking like a range assignment +void +fillAssignmentCheck2() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T> X; + + // test + // What does "no effects" mean? +} + +// Verify that the default deque constructor offers the basic exception +// guarantee. +void +test_default_ctor_exception_safety() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T, tracker_allocator<T> > X; + + T::reset(); + copy_constructor::throw_on(3); + tracker_allocator_counter::reset(); + + // test + try + { + T ref; + X a(7, ref); + VERIFY( false ); + } + catch (...) + { + } + + // assert postconditions + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown +} + +// Verify that the copy constructor offers the basic exception guarantee. +void +test_copy_ctor_exception_safety() +{ + // setup + typedef copy_tracker T; + typedef std::deque<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + T::reset(); + copy_constructor::throw_on(3); + + + // test + try + { + X u(a); + VERIFY(false); + } + catch (...) + { + } + } + + // assert postconditions + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown +} + +int main() +{ + // basic functionality and standard conformance checks + requiredTypesCheck(); + defaultConstructorCheckPOD(); + defaultConstructorCheck(); + test_default_ctor_exception_safety(); + copyConstructorCheck(); + test_copy_ctor_exception_safety(); + fillConstructorCheck(); + fillConstructorCheck2(); + rangeConstructorCheckInputIterator(); + rangeConstructorCheckForwardIterator(); + copyAssignmentCheck(); + fillAssignmentCheck(); + fillAssignmentCheck2(); + rangeAssignmentCheck(); + rangeAssignmentCheckWithException(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/assign/1.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/assign/1.cc new file mode 100644 index 000000000..31387777e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/assign/1.cc @@ -0,0 +1,51 @@ +// 2005-12-12 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2006, 2007, 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.1.1 deque constructors, copy, and assignment + +#include <deque> +#include <cstdlib> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + int data3[1000]; + fill(data3, data3 + 1000, 3); + + int data5[1000]; + fill(data5, data5 + 1000, 5); + + for (deque<int>::size_type i = 0; i < 1000; ++i) + { + deque<int> d(rand() % 500, 1); + d.assign(i, i % 2 ? 3 : 5); + + VERIFY( d.size() == i ); + VERIFY( equal(d.begin(), d.end(), i % 2 ? data3 : data5) ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc new file mode 100644 index 000000000..d545f01a3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/clear_allocator.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004, 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 <deque> +#include <ext/new_allocator.h> + +using namespace std; +using __gnu_cxx::new_allocator; + +template<typename T> + class clear_alloc : public new_allocator<T> + { + public: + + template <typename T1> + struct rebind + { typedef clear_alloc<T1> other; }; + + virtual void clear() throw() + { } + + clear_alloc() throw() + { } + + clear_alloc(clear_alloc const&) throw() : new_allocator<T>() + { } + + template<typename T1> + clear_alloc(clear_alloc<T1> const&) throw() + { } + + virtual ~clear_alloc() throw() + { this->clear(); } + + T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0) + { + this->clear(); + return new_allocator<T>::allocate(n, hint); + } + + void deallocate(T *ptr, typename new_allocator<T>::size_type n) + { + this->clear(); + new_allocator<T>::deallocate(ptr, n); + } + }; + +template<typename Container> + void Check_Container() + { + Container* pic = new Container; + int x = 230; + + while (x--) + { + pic->push_back(x); + } + + pic->get_allocator(); + + // The following has led to infinite recursions or cores. + pic->clear(); + + delete pic; + } + + +int main() +{ + Check_Container<std::deque<int, clear_alloc<int> > >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc new file mode 100644 index 000000000..0207fd717 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <deque> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<__gnu_test::NonCopyConstructible> d(1000); + VERIFY( std::distance(d.begin(), d.end()) == 1000 ); + for(auto it = d.begin(); it != d.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/moveable.cc new file mode 100644 index 000000000..57113f5fb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/moveable.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on deque (via swap). If the implementation changed +// this test may begin to fail. + +#include <deque> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::deque<int> a,b; + a.push_back(1); + b = std::move(a); + VERIFY( b.size() == 1 && b[0] == 1 && a.size() == 0 ); + + std::deque<int> c(std::move(b)); + VERIFY( c.size() == 1 && c[0] == 1 ); + VERIFY( b.size() == 0 ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/moveable2.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/moveable2.cc new file mode 100644 index 000000000..2d5edb4c2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/moveable2.cc @@ -0,0 +1,55 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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 <deque> +#include <iterator> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; +typedef std::deque<rvalstruct> test_type; + +// Empty constructor doesn't require a copy constructor +void +test01() +{ test_type d; } + +// Constructing from a range that returns rvalue references doesn't +// require a copy constructor. +void +test02(rvalstruct* begin, rvalstruct* end) +{ + test_type d(std::make_move_iterator(begin), std::make_move_iterator(end)); +} + +// Constructing from a input iterator range that returns rvalue +// references doesn't require a copy constructor either. +void +test03(input_iterator_wrapper<rvalstruct> begin, + input_iterator_wrapper<rvalstruct> end) +{ + test_type d(std::make_move_iterator(begin), std::make_move_iterator(end)); +} + +// Neither does destroying one. +void +test04(test_type* d) +{ delete d; } diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/assign1_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/assign1_neg.cc new file mode 100644 index 000000000..9a4d7d439 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/assign1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign1<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/assign2_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/assign2_neg.cc new file mode 100644 index 000000000..32eda8794 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/assign2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign2<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/assign3_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/assign3_neg.cc new file mode 100644 index 000000000..3d2b15e94 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/assign3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign3<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/assign4_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/assign4_neg.cc new file mode 100644 index 000000000..7b6204158 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/assign4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign1<__gnu_debug::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/construct1_neg.cc new file mode 100644 index 000000000..6268951d7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/construct2_neg.cc new file mode 100644 index 000000000..3b8d77547 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/construct3_neg.cc new file mode 100644 index 000000000..1187cf8b1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/construct4_neg.cc new file mode 100644 index 000000000..7d7906d05 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/insert1_neg.cc new file mode 100644 index 000000000..38b4f554a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/insert2_neg.cc new file mode 100644 index 000000000..5aa7efae6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/insert3_neg.cc new file mode 100644 index 000000000..bd854ad87 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/insert4_neg.cc new file mode 100644 index 000000000..ff88760ad --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/deque> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::deque<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/1.cc new file mode 100644 index 000000000..6af6697ea --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/1.cc @@ -0,0 +1,52 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Assignment +void test01() +{ + deque<int> v1; + deque<int> v2; + + deque<int>::iterator i = v1.end(); + VERIFY(!i._M_dereferenceable() && !i._M_singular()); + + v1 = v2; + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(v2.begin(), v2.end()); + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(17, 42); + VERIFY(i._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/2.cc new file mode 100644 index 000000000..abbf47e93 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/2.cc @@ -0,0 +1,52 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Resize +void test02() +{ + deque<int> v(10, 17); + + deque<int>::iterator before = v.begin() + 6; + deque<int>::iterator at = before + 1; + deque<int>::iterator after = at + 1; + + // Shrink + v.resize(7); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_singular()); + + // Grow + before = v.begin() + 6; + v.resize(17); + VERIFY(before._M_singular()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/3.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/3.cc new file mode 100644 index 000000000..c5a936a5b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/3.cc @@ -0,0 +1,62 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Insert +void test03() +{ + deque<int> v(10, 17); + + // Insert a single element + deque<int>::iterator before = v.begin() + 6; + deque<int>::iterator at = before + 1; + deque<int>::iterator after = at; + at = v.insert(at, 42); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Insert multiple copies + before = v.begin() + 6; + at = before + 1; + + v.insert(at, 3, 42); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); + + // Insert iterator range + static int data[] = { 2, 3, 5, 7 }; + before = v.begin() + 6; + at = before + 1; + v.insert(at, &data[0], &data[0] + 4); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc new file mode 100644 index 000000000..342f5ead7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/debug/invalidation/4.cc @@ -0,0 +1,74 @@ +// Deque iterator invalidation tests + +// Copyright (C) 2003, 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 <debug/deque> +#include <testsuite_hooks.h> + +using __gnu_debug::deque; + +bool test = true; + +// Erase +void test04() +{ + deque<int> v(20, 42); + + // Single element erase (middle) + deque<int>::iterator before = v.begin(); + deque<int>::iterator at = before + 3; + deque<int>::iterator after = at; + at = v.erase(at); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Single element erase (end) + before = v.begin(); + at = before; + after = at + 1; + at = v.erase(at); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before + 3; + v.erase(at, at + 3); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); + + // Multiple element erase at end + before = v.begin(); + at = before + 3; + v.erase(at, v.end()); + *before; + + // clear() + before = v.begin(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/init-list.cc b/libstdc++-v3/testsuite/23_containers/deque/init-list.cc new file mode 100644 index 000000000..8e25d3006 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/init-list.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <deque> +#include <testsuite_allocator.h> + +using namespace __gnu_test; + +int main() +{ + typedef std::deque<int, tracker_allocator<int> > Container; + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + Container c({ 2, 4, 1 }); + ok = check_construct_destroy("Construct from init-list", 3, 0) && ok; + ok &= (c[0] == 2); + ok &= (c[1] == 4); + } + ok = check_construct_destroy("Construct from init-list", 3, 3) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(c.begin() + 7, { 234, 42, 1 }); + ok = check_construct_destroy("Insert init-list", 3, 0) && ok; + ok &= (c[7] == 234); + } + ok = check_construct_destroy("Insert init-list", 3, 13) && ok; + + { + Container c; + tracker_allocator_counter::reset(); + c = { 13, 0, 42 }; + ok = check_construct_destroy("Assign init-list", 3, 0) && ok; + ok &= (c[0] == 13); + } + ok = check_construct_destroy("Assign init-list", 3, 3) && ok; + + return ok ? 0 : 1;; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc new file mode 100644 index 000000000..2da37a9f0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc @@ -0,0 +1,135 @@ +// 2005-11-25 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 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.1.3 deque modifiers + +#include <deque> +#include <testsuite_hooks.h> + +const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15}; +const int A3[] = {0, 2, 3, 4, 10, 11}; +const int A4[] = {4, 10, 11}; +const int A5[] = {4, 10}; +const unsigned N = sizeof(A) / sizeof(int); +const unsigned N1 = sizeof(A1) / sizeof(int); +const unsigned N2 = sizeof(A2) / sizeof(int); +const unsigned N3 = sizeof(A3) / sizeof(int); +const unsigned N4 = sizeof(A4) / sizeof(int); +const unsigned N5 = sizeof(A5) / sizeof(int); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::deque<int> deque_type; + typedef deque_type::iterator iterator_type; + + deque_type v(A, A + N); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::deque<std::deque<int> > deque_type; + typedef deque_type::iterator iterator_type; + + deque_type v, v1, v2, v3, v4, v5; + for (unsigned i = 0; i < N; ++i) + v.push_back(std::deque<int>(1, A[i])); + for (unsigned i = 0; i < N1; ++i) + v1.push_back(std::deque<int>(1, A1[i])); + for (unsigned i = 0; i < N2; ++i) + v2.push_back(std::deque<int>(1, A2[i])); + for (unsigned i = 0; i < N3; ++i) + v3.push_back(std::deque<int>(1, A3[i])); + for (unsigned i = 0; i < N4; ++i) + v4.push_back(std::deque<int>(1, A4[i])); + for (unsigned i = 0; i < N5; ++i) + v5.push_back(std::deque<int>(1, A5[i])); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), v1.begin()) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), v2.begin()) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), v3.begin()) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), v4.begin()) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), v5.begin()) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc new file mode 100644 index 000000000..2d592d7b4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc @@ -0,0 +1,114 @@ +// 2005-11-25 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 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.1.3 deque modifiers + +#include <deque> +#include <testsuite_hooks.h> + +const int A[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15}; +const int A0[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A1[] = {-5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A2[] = {-5, 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A3[] = {-5, 0, 1, 2, 8, 9, 10, 11}; +const int A4[] = {2, 8, 9, 10, 11}; +const int A5[] = {2, 8, 10, 11}; +const int A6[] = {2, 8, 10}; +const unsigned N = sizeof(A) / sizeof(int); +const unsigned N0 = sizeof(A0) / sizeof(int); +const unsigned N1 = sizeof(A1) / sizeof(int); +const unsigned N2 = sizeof(A2) / sizeof(int); +const unsigned N3 = sizeof(A3) / sizeof(int); +const unsigned N4 = sizeof(A4) / sizeof(int); +const unsigned N5 = sizeof(A5) / sizeof(int); +const unsigned N6 = sizeof(A6) / sizeof(int); + +template<int Size> + class My_class + { + double dummy[Size]; + int data; + + public: + My_class(int num) + : data(num) { } + + operator int() const + { return data; } + }; + +template<typename T> + void + test01() + { + bool test __attribute__((unused)) = true; + + typedef std::deque<T> deque_type; + typedef typename deque_type::iterator iterator_type; + + deque_type v(A, A + N); + + iterator_type it0 = v.erase(v.begin() + 1, v.begin() + 4); + VERIFY( it0 == v.begin() + 1 ); + VERIFY( v.size() == N0 ); + VERIFY( std::equal(v.begin(), v.end(), A0) ); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + iterator_type it3 = v.erase(v.begin() + 8, v.end()); + VERIFY( it3 == v.begin() + 8 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + iterator_type it6 = v.erase(v.begin() + 3, v.end()); + VERIFY( it6 == v.begin() + 3 ); + VERIFY( v.size() == N6 ); + VERIFY( std::equal(v.begin(), v.end(), A6) ); + + iterator_type it7 = v.erase(v.begin(), v.end()); + VERIFY( it7 == v.begin() ); + VERIFY( v.empty() ); + } + +int main() +{ + test01<My_class<1> >(); + test01<My_class<8> >(); + test01<My_class<32> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc new file mode 100644 index 000000000..79a046ed7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2007, 2009, 2010, 2011 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.1.3 deque modifiers + +#include <deque> +#include <testsuite_hooks.h> + +void erase(size_t num_elm, size_t elm_strt, size_t elm_end) +{ + bool test __attribute__((unused)) = true; + using __gnu_test::copy_tracker; + using __gnu_test::assignment_operator; + + std::deque<copy_tracker> x(num_elm); + copy_tracker::reset(); + + x.erase(x.begin() + elm_strt, x.begin() + elm_end); + + const size_t min_num_cpy + = elm_strt == elm_end ? 0 : std::min(elm_strt, num_elm - elm_end); + + VERIFY( assignment_operator::count() == min_num_cpy ); +} + +// http://gcc.gnu.org/ml/libstdc++/2007-01/msg00098.html +void test01() +{ + for (size_t num_elm = 0; num_elm <= 10; ++num_elm) + for (size_t elm_strt = 0; elm_strt <= num_elm; ++elm_strt) + for (size_t elm_end = elm_strt; elm_end <= num_elm; ++elm_end) + erase(num_elm, elm_strt, elm_end); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc new file mode 100644 index 000000000..f534758a9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-09-26 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2011 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 <deque> +#include <testsuite_rvalref.h> + +// libstdc++/50529 +void test01() +{ + std::deque<__gnu_test::rvalstruct> d(10); + + for (auto it = d.begin(); it != d.end(); ++it) + d.erase(it, it); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc new file mode 100644 index 000000000..e631000f6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <deque> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::deque<copycounter> a(40); + copycounter::copycount = 0; + + a.erase(a.begin() + 20); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 1); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin() + 10, a.end() - 10); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.begin() + 5); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 5, a.end()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.end()); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc new file mode 100644 index 000000000..6519600fb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc @@ -0,0 +1,134 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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 <deque> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; + +// Test deque::push_back makes no unneeded copies. +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<copycounter> a; + copycounter c(1); + copycounter::copycount = 0; + for(int i = 0; i < 1000; ++i) + a.push_back(c); + VERIFY(copycounter::copycount == 1000); +} + +// Test deque::push_front makes no unneeded copies. +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::deque<copycounter> a; + copycounter c(1); + copycounter::copycount = 0; + for(int i = 0; i < 1000; ++i) + a.push_front(c); + VERIFY(copycounter::copycount == 1000); +} + +// Test deque::insert makes no unneeded copies. +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::deque<copycounter> a(1000); + copycounter c(1); + copycounter::copycount = 0; + a.insert(a.begin(),c); + a.insert(a.end(),c); + for(int i = 0; i < 500; ++i) + a.insert(a.begin() + i, c); + VERIFY(copycounter::copycount == 502); +} + +// Test deque::insert(iterator, count, value) makes no unneeded copies +// when it has to also reallocate the deque's internal buffer. +void +test04() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::deque<copycounter> a(10, c); + copycounter::copycount = 0; + a.insert(a.begin(), 20, c); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70); + // NOTE : These values are each one higher than might be expected, as + // deque::insert(iterator, count, value) copies the value it is given + // when it has to move elements in the deque in case that value is + // in the deque. + + // Near the start + a.insert(a.begin() + 10, 100, c); + VERIFY(copycounter::copycount == 170 + 1); + // Near the end + a.insert(a.end() - 10, 1000, c); + VERIFY(copycounter::copycount == 1170 + 2); +} + +// Test deque::insert(iterator, count, value) makes no unneeded copies +// when it doesn't have to reallocate the deque's internal buffer. +void +test05() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::deque<copycounter> a(10, c); + copycounter::copycount = 0; + //a.reserve(1000); + a.insert(a.begin(), 20, c); + VERIFY(copycounter::copycount == 20 ); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70 ); + + // NOTE : These values are each one higher than might be expected, as + // deque::insert(iterator, count, value) copies the value it is given + // when it has to move elements in the deque in case that value is + // in the deque. + // Near the start + a.insert(a.begin() + 10, 100, c); + VERIFY(copycounter::copycount == 170 + 1); + // Near the end + a.insert(a.end() - 10, 200, c); + VERIFY(copycounter::copycount == 370 + 2); +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc new file mode 100644 index 000000000..3b176c869 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2004, 2005, 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 <deque> +#include <testsuite_hooks.h> + +struct T { int i; }; + +int swap_calls; + +namespace std +{ + template<> + void + deque<T, allocator<T> >::swap(deque<T, allocator<T> >&) + { ++swap_calls; } +} + +// Should use deque specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::deque<T> A; + std::deque<T> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use deque specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + deque<T> A; + deque<T> B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc new file mode 100644 index 000000000..5721e2a53 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc @@ -0,0 +1,132 @@ +// 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.1.3 deque::swap + +#include <deque> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef deque<char, my_alloc> my_deque; + + 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); + + my_deque::size_type size01, size02; + + my_alloc alloc01(1); + + my_deque deq01(alloc01); + size01 = deq01.size(); + my_deque deq02(alloc01); + size02 = deq02.size(); + + deq01.swap(deq02); + VERIFY( deq01.size() == size02 ); + VERIFY( deq01.empty() ); + VERIFY( deq02.size() == size01 ); + VERIFY( deq02.empty() ); + + my_deque deq03(alloc01); + size01 = deq03.size(); + my_deque deq04(title02, title02 + N2, alloc01); + size02 = deq04.size(); + + deq03.swap(deq04); + VERIFY( deq03.size() == size02 ); + VERIFY( equal(deq03.begin(), deq03.end(), title02) ); + VERIFY( deq04.size() == size01 ); + VERIFY( deq04.empty() ); + + my_deque deq05(title01, title01 + N1, alloc01); + size01 = deq05.size(); + my_deque deq06(title02, title02 + N2, alloc01); + size02 = deq06.size(); + + deq05.swap(deq06); + VERIFY( deq05.size() == size02 ); + VERIFY( equal(deq05.begin(), deq05.end(), title02) ); + VERIFY( deq06.size() == size01 ); + VERIFY( equal(deq06.begin(), deq06.end(), title01) ); + + my_deque deq07(title01, title01 + N1, alloc01); + size01 = deq07.size(); + my_deque deq08(title03, title03 + N3, alloc01); + size02 = deq08.size(); + + deq07.swap(deq08); + VERIFY( deq07.size() == size02 ); + VERIFY( equal(deq07.begin(), deq07.end(), title03) ); + VERIFY( deq08.size() == size01 ); + VERIFY( equal(deq08.begin(), deq08.end(), title01) ); + + my_deque deq09(title03, title03 + N3, alloc01); + size01 = deq09.size(); + my_deque deq10(title04, title04 + N4, alloc01); + size02 = deq10.size(); + + deq09.swap(deq10); + VERIFY( deq09.size() == size02 ); + VERIFY( equal(deq09.begin(), deq09.end(), title04) ); + VERIFY( deq10.size() == size01 ); + VERIFY( equal(deq10.begin(), deq10.end(), title03) ); + + my_deque deq11(title04, title04 + N4, alloc01); + size01 = deq11.size(); + my_deque deq12(title01, title01 + N1, alloc01); + size02 = deq12.size(); + + deq11.swap(deq12); + VERIFY( deq11.size() == size02 ); + VERIFY( equal(deq11.begin(), deq11.end(), title01) ); + VERIFY( deq12.size() == size01 ); + VERIFY( equal(deq12.begin(), deq12.end(), title04) ); + + my_deque deq13(title03, title03 + N3, alloc01); + size01 = deq13.size(); + my_deque deq14(title03, title03 + N3, alloc01); + size02 = deq14.size(); + + deq13.swap(deq14); + VERIFY( deq13.size() == size02 ); + VERIFY( equal(deq13.begin(), deq13.end(), title03) ); + VERIFY( deq14.size() == size01 ); + VERIFY( equal(deq14.begin(), deq14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc new file mode 100644 index 000000000..e4e1cba7e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc @@ -0,0 +1,161 @@ +// 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.1.3 deque::swap + +#include <deque> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef deque<char, my_alloc> my_deque; + + 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); + + my_deque::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_deque deq01(alloc01); + size01 = deq01.size(); + personality01 = deq01.get_allocator().get_personality(); + my_deque deq02(alloc02); + size02 = deq02.size(); + personality02 = deq02.get_allocator().get_personality(); + + deq01.swap(deq02); + VERIFY( deq01.size() == size02 ); + VERIFY( deq01.empty() ); + VERIFY( deq02.size() == size01 ); + VERIFY( deq02.empty() ); + VERIFY( deq01.get_allocator().get_personality() == personality02 ); + VERIFY( deq02.get_allocator().get_personality() == personality01 ); + + my_deque deq03(alloc02); + size01 = deq03.size(); + personality01 = deq03.get_allocator().get_personality(); + my_deque deq04(title02, title02 + N2, alloc01); + size02 = deq04.size(); + personality02 = deq04.get_allocator().get_personality(); + + deq03.swap(deq04); + VERIFY( deq03.size() == size02 ); + VERIFY( equal(deq03.begin(), deq03.end(), title02) ); + VERIFY( deq04.size() == size01 ); + VERIFY( deq04.empty() ); + VERIFY( deq03.get_allocator().get_personality() == personality02 ); + VERIFY( deq04.get_allocator().get_personality() == personality01 ); + + my_deque deq05(title01, title01 + N1, alloc01); + size01 = deq05.size(); + personality01 = deq05.get_allocator().get_personality(); + my_deque deq06(title02, title02 + N2, alloc02); + size02 = deq06.size(); + personality02 = deq06.get_allocator().get_personality(); + + deq05.swap(deq06); + VERIFY( deq05.size() == size02 ); + VERIFY( equal(deq05.begin(), deq05.end(), title02) ); + VERIFY( deq06.size() == size01 ); + VERIFY( equal(deq06.begin(), deq06.end(), title01) ); + VERIFY( deq05.get_allocator().get_personality() == personality02 ); + VERIFY( deq06.get_allocator().get_personality() == personality01 ); + + my_deque deq07(title01, title01 + N1, alloc02); + size01 = deq07.size(); + personality01 = deq07.get_allocator().get_personality(); + my_deque deq08(title03, title03 + N3, alloc01); + size02 = deq08.size(); + personality02 = deq08.get_allocator().get_personality(); + + deq07.swap(deq08); + VERIFY( deq07.size() == size02 ); + VERIFY( equal(deq07.begin(), deq07.end(), title03) ); + VERIFY( deq08.size() == size01 ); + VERIFY( equal(deq08.begin(), deq08.end(), title01) ); + VERIFY( deq07.get_allocator().get_personality() == personality02 ); + VERIFY( deq08.get_allocator().get_personality() == personality01 ); + + my_deque deq09(title03, title03 + N3, alloc01); + size01 = deq09.size(); + personality01 = deq09.get_allocator().get_personality(); + my_deque deq10(title04, title04 + N4, alloc02); + size02 = deq10.size(); + personality02 = deq10.get_allocator().get_personality(); + + deq09.swap(deq10); + VERIFY( deq09.size() == size02 ); + VERIFY( equal(deq09.begin(), deq09.end(), title04) ); + VERIFY( deq10.size() == size01 ); + VERIFY( equal(deq10.begin(), deq10.end(), title03) ); + VERIFY( deq09.get_allocator().get_personality() == personality02 ); + VERIFY( deq10.get_allocator().get_personality() == personality01 ); + + my_deque deq11(title04, title04 + N4, alloc02); + size01 = deq11.size(); + personality01 = deq11.get_allocator().get_personality(); + my_deque deq12(title01, title01 + N1, alloc01); + size02 = deq12.size(); + personality02 = deq12.get_allocator().get_personality(); + + deq11.swap(deq12); + VERIFY( deq11.size() == size02 ); + VERIFY( equal(deq11.begin(), deq11.end(), title01) ); + VERIFY( deq12.size() == size01 ); + VERIFY( equal(deq12.begin(), deq12.end(), title04) ); + VERIFY( deq11.get_allocator().get_personality() == personality02 ); + VERIFY( deq12.get_allocator().get_personality() == personality01 ); + + my_deque deq13(title03, title03 + N3, alloc01); + size01 = deq13.size(); + personality01 = deq13.get_allocator().get_personality(); + my_deque deq14(title03, title03 + N3, alloc02); + size02 = deq14.size(); + personality02 = deq14.get_allocator().get_personality(); + + deq13.swap(deq14); + VERIFY( deq13.size() == size02 ); + VERIFY( equal(deq13.begin(), deq13.end(), title03) ); + VERIFY( deq14.size() == size01 ); + VERIFY( equal(deq14.begin(), deq14.end(), title03) ); + VERIFY( deq13.get_allocator().get_personality() == personality02 ); + VERIFY( deq14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc b/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc new file mode 100644 index 000000000..5db862186 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/operators/1.cc @@ -0,0 +1,62 @@ +// 2002-05-18 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2002, 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.1 deque operators + +#include <deque> +#include <testsuite_hooks.h> + +// libstdc++/6503 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<int> d(2); + typedef std::deque<int>::iterator iter; + typedef std::deque<int>::const_iterator constiter; + + iter beg = d.begin(); + iter end = d.end(); + constiter constbeg = d.begin(); + constiter constend = d.end(); + + VERIFY( beg == constbeg ); + VERIFY( constend == end ); + + VERIFY( beg != constend ); + VERIFY( constbeg != end ); + + VERIFY( beg < constend ); + VERIFY( constbeg < end ); + + VERIFY( end > constbeg ); + VERIFY( constend > beg ); + + VERIFY( end >= constend ); + VERIFY( constbeg >= beg ); + + VERIFY( beg <= constbeg ); + VERIFY( constend <= end ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/operators/2.cc b/libstdc++-v3/testsuite/23_containers/deque/operators/2.cc new file mode 100644 index 000000000..4db5e0ee2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/operators/2.cc @@ -0,0 +1,50 @@ +// 2002-05-18 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2002, 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.1 deque operators + +#include <deque> +#include <testsuite_hooks.h> + +// libstdc++/7186 +void test02() +{ + bool test __attribute__((unused)) = true; + + std::deque<int> d(2); + typedef std::deque<int>::iterator iter; + typedef std::deque<int>::const_iterator constiter; + + iter beg = d.begin(); + iter end = d.end(); + constiter constbeg = d.begin(); + constiter constend = d.end(); + + VERIFY( beg - constbeg == 0 ); + VERIFY( constend - end == 0 ); + + VERIFY( end - constbeg > 0 ); + VERIFY( constend - beg > 0 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/range_access.cc b/libstdc++-v3/testsuite/23_containers/deque/range_access.cc new file mode 100644 index 000000000..7c7588954 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <deque> + +void +test01() +{ + std::deque<int> d{1, 2, 3}; + std::begin(d); + std::end(d); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/citerators.cc new file mode 100644 index 000000000..4a05e6060 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <deque> +#include <testsuite_containers.h> + +int main() +{ + typedef std::deque<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc new file mode 100644 index 000000000..ecd115e3a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc @@ -0,0 +1,35 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1661 } +// { dg-excess-errors "" } + +#include <deque> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + std::deque<A> d; + d.assign(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor.cc new file mode 100644 index 000000000..e7a4a2be8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor.cc @@ -0,0 +1,27 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + +// { dg-do compile } + +#include <deque> + +void f() +{ + std::deque<int> v(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc new file mode 100644 index 000000000..4de01c826 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc @@ -0,0 +1,29 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1594 } +// { dg-excess-errors "" } + +#include <deque> + +void f() +{ + std::deque<std::deque<int> > d(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc new file mode 100644 index 000000000..78eeb8dbc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc @@ -0,0 +1,30 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1594 } +// { dg-excess-errors "" } + +#include <deque> +#include <utility> + +void f() +{ + std::deque<std::deque<std::pair<char, char> > > d('a', 'b'); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc new file mode 100644 index 000000000..f29152cb7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc @@ -0,0 +1,36 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1745 } +// { dg-excess-errors "" } + +#include <deque> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + std::deque<A> d; + d.insert(d.begin(), 10, 1); +} + diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/basic.cc new file mode 100644 index 000000000..25629c156 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/basic.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <deque> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::deque<value_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..aa3a8ba87 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/generation_prohibited.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// Copyright (C) 2009, 2010 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 <deque> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::deque<value_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..14892344e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/exception/propagation_consistent.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-do run { xfail *-*-* } } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <deque> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::deque<value_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..c672777ba --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <deque> + +// { dg-do compile } + +template class std::deque<int>; diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..219970082 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <deque> + +template class std::deque<int>; diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..82efd2605 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/2.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <deque> +#include <testsuite_api.h> + +// { dg-do compile } + +// N.B. In C++0x mode we cannot instantiate with T == NonDefaultConstructible +// because of 23.3.2.1.4 +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +template class std::deque<__gnu_test::NonDefaultConstructible>; +#endif diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..8307e21d6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <deque> + +// { dg-do compile } + +// libstdc++/21770 +template class std::deque<int, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..4685ae142 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/explicit_instantiation/4.cc @@ -0,0 +1,30 @@ +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + + +// This file tests explicit instantiation of library containers + +#include <deque> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::deque<__gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..bc0c9823c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 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/>. + + +// This file tests user specialization of library containers + +#include <deque> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Allocator> + class deque<user_type, Allocator> {}; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/typedefs.cc new file mode 100644 index 000000000..6263951fe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <deque> + +// Check container for required typedefs. +__gnu_test::types<std::deque<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc new file mode 100644 index 000000000..eed7f8735 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc @@ -0,0 +1,52 @@ +// 2005-12-18 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/>. + +// { dg-do compile } + +#include <deque> +#include <testsuite_greedy_ops.h> + +int main() +{ + std::deque<greedy_ops::X> d(5); + const std::deque<greedy_ops::X> e(1); + + d[0]; + e[0]; + d.size(); + d.erase(d.begin()); + d.resize(1); + d.assign(1, greedy_ops::X()); + d.insert(d.begin(), greedy_ops::X()); + d.insert(d.begin(), 1, greedy_ops::X()); + d.insert(d.begin(), e.begin(), e.end()); + d = e; + + std::deque<greedy_ops::X>::iterator it; + it == it; + it != it; + it < it; + it <= it; + it > it; + it >= it; + it - it; + it + 1; + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/capacity/1.cc new file mode 100644 index 000000000..702acfe34 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/capacity/1.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010 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.3.n forward_list capacity [lib.forward_list.capacity] + +#include <forward_list> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<double> fld; + VERIFY(fld.empty() == true); + + fld.push_front(1.0); + VERIFY(fld.empty() == false); + + fld.resize(0); + VERIFY(fld.empty() == true); + +#if defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_PROFILE) + using std::_GLIBCXX_STD_C::_Fwd_list_node; +#else + using std::_Fwd_list_node; +#endif + + VERIFY( (fld.max_size() + == std::allocator<_Fwd_list_node<double> >().max_size()) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/capacity/resize_size.cc b/libstdc++-v3/testsuite/23_containers/forward_list/capacity/resize_size.cc new file mode 100644 index 000000000..e22af3cbc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/capacity/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <forward_list> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<__gnu_test::NonCopyConstructible> fl; + VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); + + fl.resize(1000); + VERIFY( std::distance(fl.begin(), fl.end()) == 1000 ); + for(auto it = fl.begin(); it != fl.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/comparable.cc b/libstdc++-v3/testsuite/23_containers/forward_list/comparable.cc new file mode 100644 index 000000000..d05461917 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/comparable.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on list (via swap). If the implementation changed +// this test may begin to fail. + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +int main() +{ + std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; + std::forward_list<double> b = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; + + VERIFY((a == b) == false); + VERIFY((a < b) == true); + VERIFY((a != b) == true); + VERIFY((a > b) == false); + VERIFY((a >= b) == false); + VERIFY((a <= b) == true); + + VERIFY((b == a) == false); + VERIFY((b < a) == false); + VERIFY((b != a) == true); + VERIFY((b > a) == true); + VERIFY((b >= a) == true); + VERIFY((b <= a) == false); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/1.cc new file mode 100644 index 000000000..7dec2a4b4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/1.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Default construction +void +test01() +{ + std::forward_list<double> fld; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/2.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/2.cc new file mode 100644 index 000000000..eb447274b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/2.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Construction from iterator range +// Copy construction with allocator +void +test01() +{ + const int ni = 10; + int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + std::forward_list<int> flccin(i, i+ni); + std::forward_list<int> flcc(flccin, std::allocator<int>()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/3.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/3.cc new file mode 100644 index 000000000..6197731cb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/3.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Move construction with allocator +void +test01() +{ + const int ni = 10; + int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + std::forward_list<int> flmc(std::forward_list<int>(i, i+ni), std::allocator<int>()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/4.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/4.cc new file mode 100644 index 000000000..3d23719ca --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/4.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Construction from given number of default item +void +test01() +{ + std::forward_list<double> flvd(10); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/5.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/5.cc new file mode 100644 index 000000000..ca7b5f7e6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/5.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Construction from given number of given item +void +test01() +{ + std::forward_list<float> flv(10, 5.0F); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/6.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/6.cc new file mode 100644 index 000000000..f385661f2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/6.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Construction from iterator range +void +test01() +{ + const int ni = 10; + int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + std::forward_list<int> fl(i, i+ni); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/7.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/7.cc new file mode 100644 index 000000000..f03779134 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/7.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Copy construction +void +test01() +{ + const int ni = 10; + int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + std::forward_list<int> fl(i, i+ni); + std::forward_list<int> flc(fl); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/8.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/8.cc new file mode 100644 index 000000000..3cf4288f4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/8.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// Move construction +void +test01() +{ + const int ni = 10; + int i[ni] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + std::forward_list<int> fl(i, i+ni); + std::forward_list<int> flm(std::move(fl)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/9.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/9.cc new file mode 100644 index 000000000..ce7bb8597 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/9.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following. +// Construction from initializer list +void +test01() +{ + std::forward_list<double> flil({1.0, 2.0, 3.0, 4.0, 5.0}); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/cons_size.cc new file mode 100644 index 000000000..3d07f6720 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <forward_list> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<__gnu_test::NonCopyConstructible> fl(1000); + VERIFY( std::distance(fl.begin(), fl.end()) == 1000 ); + for(auto it = fl.begin(); it != fl.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/moveable.cc new file mode 100644 index 000000000..e680d3c8e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/moveable.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on list (via swap). If the implementation changed +// this test may begin to fail. + +#include <forward_list> +#include <utility> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +int main() +{ + std::forward_list<int> a, b; + a.push_front(1); + + b = std::move(a); + VERIFY(b.empty() == false); + VERIFY(*b.begin() == 1); + VERIFY(a.empty() == true); + + std::forward_list<int> c(std::move(b)); + VERIFY(c.empty() == false); + (*c.begin() == 1 ); + VERIFY( b.empty() == true ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/clear.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/clear.cc new file mode 100644 index 000000000..57e0e2f53 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/clear.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Check that iterators ownership is correctly manage on swap. +#include <forward_list> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + std::forward_list<int> fl{1, 2, 3}; + + auto before = fl.before_begin(); + auto end = fl.end(); + fl.clear(); + + VERIFY( end == fl.end() ); + VERIFY( before == fl.before_begin() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after1_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after1_neg.cc new file mode 100644 index 000000000..8f3607619 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after1_neg.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<int> fl1{1, 2, 3}; + + auto it = fl1.begin(); + VERIFY( *it == 1 ); + + fl1.erase_after(fl1.before_begin()); + + VERIFY( *it == 1 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after2_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after2_neg.cc new file mode 100644 index 000000000..2efaa74ca --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after2_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + fl1.erase_after(fl1.end()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after3_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after3_neg.cc new file mode 100644 index 000000000..b17707e61 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after3_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1}; + fl1.erase_after(fl1.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after4_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after4_neg.cc new file mode 100644 index 000000000..087abcecd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after4_neg.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{1, 2, 3}; + + fl1.erase_after(fl1.before_begin(), fl2.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after5_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after5_neg.cc new file mode 100644 index 000000000..46a74da5f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after5_neg.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{1, 2, 3}; + + fl1.erase_after(fl2.before_begin(), fl2.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after6_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after6_neg.cc new file mode 100644 index 000000000..a057c9cfa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after6_neg.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + + fl1.erase_after(fl1.before_begin(), fl1.before_begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after7_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after7_neg.cc new file mode 100644 index 000000000..49a48f74d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after7_neg.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + + fl1.erase_after(fl1.end(), fl1.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after8_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after8_neg.cc new file mode 100644 index 000000000..a1ff667f5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after8_neg.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + + fl1.erase_after(fl1.begin(), fl1.before_begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after9_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after9_neg.cc new file mode 100644 index 000000000..3d25787de --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after9_neg.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + + auto it = fl1.begin(); + ++it; + fl1.erase_after(it, fl1.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after1_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after1_neg.cc new file mode 100644 index 000000000..84d39ae99 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after1_neg.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{1, 2, 3}; + + fl1.insert_after(fl1.before_begin(), fl2.before_begin(), fl2.end()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after2_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after2_neg.cc new file mode 100644 index 000000000..18e1670cc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after2_neg.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{0}; + + fl1.insert_after(fl1.before_begin(), fl2.begin(), fl2.before_begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after3_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after3_neg.cc new file mode 100644 index 000000000..325028c72 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after3_neg.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + + fl1.insert_after(fl1.end(), 4); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_constructor.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_constructor.cc new file mode 100644 index 000000000..6238f6f8f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_constructor.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Check that iterators ownership is correctly manage on swap. +#include <forward_list> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + std::forward_list<int> fl1{1, 3, 5}; + + auto flit = fl1.before_begin(); + std::forward_list<int> fl2(std::move(fl1)); + +#if !_GLIBCXX_DEBUG + VERIFY( flit == fl1.before_begin() ); +#endif +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after.cc new file mode 100644 index 000000000..8a7d49f94 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Check that iterators ownership is correctly manage on swap. +#include <forward_list> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{4, 5, 6}; + + auto before = fl1.before_begin(); + auto end = fl1.end(); + fl2.splice_after(fl2.before_begin(), std::move(fl1)); + + VERIFY( before == fl1.before_begin() ); + VERIFY( end == fl1.end() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after1_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after1_neg.cc new file mode 100644 index 000000000..d0cee48b2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after1_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + fl1.splice_after(fl1.begin(), std::move(fl1)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after2_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after2_neg.cc new file mode 100644 index 000000000..545562322 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after2_neg.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{1, 2, 3}; + + fl1.splice_after(fl1.before_begin(), std::move(fl2), fl1.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after3_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after3_neg.cc new file mode 100644 index 000000000..1e63e90a5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after3_neg.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{1, 2, 3}; + + fl1.splice_after(fl1.before_begin(), std::move(fl2), fl2.end()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after4_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after4_neg.cc new file mode 100644 index 000000000..9582a8b3e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/splice_after4_neg.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +// Copyright (C) 2010 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 <forward_list> + +void +test01() +{ + std::forward_list<int> fl1{1, 2, 3}; + std::forward_list<int> fl2{1, 2, 3}; + + fl1.splice_after(fl1.before_begin(), + std::move(fl2), ++(++fl2.begin()), ++fl2.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/swap.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/swap.cc new file mode 100644 index 000000000..85884c0af --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/swap.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Check that iterators ownership is correctly manage on swap. +#include <vector> +#include <forward_list> +#include <iostream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + std::forward_list<int> fl1{1, 3, 5}; + std::forward_list<int> fl2{2, 4, 6}; + + std::vector<std::forward_list<int>::iterator> fl1_its; + fl1_its.push_back(fl1.before_begin()); + for (std::forward_list<int>::iterator it = fl1.begin(); + it != fl1.end(); ++it) + { + fl1_its.push_back(it); + } + fl1_its.push_back(fl1.end()); + + std::vector<std::forward_list<int>::iterator> fl2_its; + fl2_its.push_back(fl2.before_begin()); + for (std::forward_list<int>::iterator it = fl2.begin(); + it != fl2.end(); ++it) + { + fl2_its.push_back(it); + } + fl2_its.push_back(fl2.end()); + + fl1.swap(fl2); + + auto fit = fl1.before_begin(); + // before-begin iterator is not transfered: + // TODO: Validate with LWG group how before begin should be + // treated. + VERIFY( fit == fl1_its[0] ); + // All other iterators are, even paste-the-end ones: + for (size_t i = 1; i != fl2_its.size(); ++i) + { + VERIFY( ++fit == fl2_its[i] ); + } + + fit = fl2.before_begin(); + // TODO: Validate with LWG group how before begin should be + // treated. + VERIFY( fit == fl2_its[0] ); + for (size_t i = 1; i != fl1_its.size(); ++i) + { + VERIFY( ++fit == fl1_its[i] ); + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/1.cc new file mode 100644 index 000000000..09ad6aa6e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/1.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +#include <array> + +bool test __attribute__((unused)) = true; + +class PathPoint +{ +public: + PathPoint(char t, std::array<double, 3> & c) + : type(t), coord(c) { } + char getType() const { return type; } +private: + char type; + std::array<double, 3> coord; +}; + +// This test verifies the following. +// emplace_front +// pop_front +// emplace_after +void +test01() +{ + std::forward_list<PathPoint> path; + std::array<double, 3> coord1 = { { 0.0, 1.0, 2.0 } }; + path.emplace_front('a', coord1); + + std::forward_list<PathPoint>::const_iterator pos = path.cbegin(); + + std::array<double, 3> coord2 = { { 3.0, 4.0, 5.0 } }; + path.emplace_after(pos, 'b', coord2); + + VERIFY(path.front().getType() == 'a'); + + path.pop_front(); + + VERIFY(path.front().getType() == 'b'); + + path.pop_front(); + + VERIFY(path.empty() == true); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/2.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/2.cc new file mode 100644 index 000000000..b6c6e35eb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/2.cc @@ -0,0 +1,154 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +#include <string> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// insert_after single item +// before_begin iterator +void +test01() +{ + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::forward_list<int>::iterator ret = fl.insert_after(fl.before_begin(), + 42); + VERIFY( ret == fl.begin() ); + VERIFY( fl.front() == 42 ); +} + +// This test verifies the following: +void +test02() +{ + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::forward_list<int>::const_iterator pos = fl.cbegin(); + ++pos; + VERIFY( *pos == 1 ); + + std::forward_list<int>::iterator ret = fl.insert_after(pos, 0, 42); + VERIFY( ret == pos ); + + ret = fl.insert_after(pos, 5, 42); + VERIFY( *pos == 1 ); + + ++pos; + VERIFY( *pos == 42 ); + ++pos; + ++pos; + ++pos; + ++pos; + VERIFY( *pos == 42 ); + VERIFY( ret == pos ); + ++pos; + VERIFY( *pos == 2 ); +} + +// This test verifies the following: +void +test03() +{ + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::forward_list<int>::const_iterator pos = fl.cbegin(); + ++pos; + VERIFY( *pos == 1 ); + + int i[3] = {666, 777, 888}; + std::forward_list<int>::iterator ret = fl.insert_after(pos, i, i); + VERIFY( ret == pos ); + + ret = fl.insert_after(pos, i, i + 3); + VERIFY( *pos == 1 ); + + ++pos; + ++pos; + ++pos; + VERIFY( *pos == 888 ); + VERIFY( ret == pos ); + ++pos; + VERIFY( *pos == 2 ); +} + +// This test verifies the following: +void +test04() +{ + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::forward_list<int>::const_iterator pos = fl.cbegin(); + ++pos; + VERIFY( *pos == 1 ); + + std::forward_list<int>::iterator ret = fl.insert_after(pos, { }); + VERIFY( ret == pos); + + ret = fl.insert_after(pos, {-1, -2, -3, -4, -5}); + VERIFY( *pos == 1); + + ++pos; + ++pos; + ++pos; + VERIFY( *pos == -3 ); + ++pos; + ++pos; + VERIFY( ret == pos ); + ++pos; + VERIFY( *pos == 2 ); +} + +// This test verifies the following: +void +test05() +{ + std::forward_list<std::string> fl({"AAA", "BBB", "CCC"}); + + std::forward_list<std::string>::const_iterator pos = fl.cbegin(); + ++pos; + VERIFY( *pos == "BBB" ); + + std::string x( "XXX" ); + std::forward_list<std::string>::iterator ret + = fl.insert_after(pos, std::move(x)); + VERIFY( *pos == "BBB" ); + ++pos; + VERIFY( ret == pos ); + VERIFY( *pos == "XXX" ); + ++pos; + VERIFY( *pos == "CCC" ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/3.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/3.cc new file mode 100644 index 000000000..349be4c2e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/3.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +// This test verifies the following: +// cbegin +// erase_after one iterator +// pos is useable and points to current element +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::forward_list<int>::const_iterator pos = fl.cbegin(); + ++pos; + VERIFY( *pos == 1 ); + + std::forward_list<int>::iterator pos2 = fl.erase_after(pos); + + VERIFY( *pos == 1 ); + ++pos; + VERIFY( *pos == 3 ); + VERIFY( pos == pos2 ); +} + +// This test verifies the following: +// cbegin +// erase_after iterator range +// pos is useable and points to current element +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::forward_list<int>::const_iterator pos = fl.cbegin(); + ++pos; + VERIFY( *pos == 1 ); + + std::forward_list<int>::iterator stop = fl.begin(); + ++stop; + ++stop; + ++stop; + ++stop; + VERIFY( *stop == 4 ); + + std::forward_list<int>::iterator pos2 = fl.erase_after(pos, stop); + + VERIFY( pos2 == stop ); + VERIFY( *pos == 1 ); + ++pos; + VERIFY( *pos == 4 ); + VERIFY( std::distance(fl.begin(), fl.end()) == 8 ); + + std::forward_list<int>::iterator pos3 + = fl.erase_after(pos, fl.end()); + VERIFY( pos3 == fl.end() ); + VERIFY( ++pos == fl.end() ); + VERIFY( std::distance(fl.begin(), fl.end()) == 3 ); + + std::forward_list<int>::iterator pos4 + = fl.erase_after(fl.before_begin(), pos); + VERIFY( pos4 == pos ); + VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); + VERIFY( fl.empty() ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/4.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/4.cc new file mode 100644 index 000000000..554ac030d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/4.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// swap +void +test01() +{ + std::forward_list<int> fl1({0, 1, 2, 3, 4, 5}); + std::forward_list<int> fl2({666, 777, 888}); + + fl1.swap(fl2); + + VERIFY(fl1.front() == 666); + VERIFY(fl2.front() == 0); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/5.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/5.cc new file mode 100644 index 000000000..26a422665 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/5.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// clear +void +test01() +{ + std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + VERIFY(fl.empty() == false); + + fl.clear(); + + VERIFY(fl.empty() == true); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc new file mode 100644 index 000000000..c4794d358 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/1.cc @@ -0,0 +1,106 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// +void +test01() +{ + std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; + std::forward_list<double>::const_iterator posa = a.cbefore_begin(); + + std::forward_list<double> x = {666.0, 777.0, 888.0}; + + a.splice_after(posa, std::move(x)); + + ++posa; + VERIFY(*posa == 666.0); + + VERIFY(x.empty() == true); +} + +// This test verifies the following: +// +void +test02() +{ + std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; + std::forward_list<double>::const_iterator posa = a.cbefore_begin(); + ++posa; + VERIFY(*posa == 0.0); + + std::forward_list<double> y = {10.0, 11.0, 12.0, 13.0, 14.0, 15.0}; + std::forward_list<double>::const_iterator befy = y.cbefore_begin(); + ++befy; + VERIFY(*befy == 10.0); + std::forward_list<double>::const_iterator endy = befy; + ++endy; + ++endy; + ++endy; + ++endy; + VERIFY(*endy == 14.0); + + a.splice_after(posa, std::move(y), befy, endy); + VERIFY(*posa == 0.0); + + VERIFY(*befy == 10.0); + ++befy; + VERIFY(*befy == 15.0); +} + +// This test verifies the following: +// +void +test03() +{ + std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; + std::forward_list<double>::const_iterator posa = a.cbefore_begin(); + ++posa; + ++posa; + VERIFY(*posa == 1.0); + + std::forward_list<double> z = {42.0, 43.0, 44.0}; + std::forward_list<double>::const_iterator posz = z.begin(); + VERIFY(*posz == 42.0); + + a.splice_after(posa, std::move(z), posz); + VERIFY(*posa == 1.0); + ++posa; + VERIFY(*posa == 43.0); + + VERIFY(*posz == 42.0); + ++posz; + VERIFY(*posz == 44.0); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc new file mode 100644 index 000000000..fe12af9aa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/2.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// remove +void +test01() +{ + std::forward_list<int> fl ={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + fl.remove(7); + + std::forward_list<int>::const_iterator pos = fl.cbefore_begin(); + for (std::size_t i = 0; i < 7; ++i) + ++pos; + VERIFY(*pos == 6); + + ++pos; + VERIFY(*pos == 8); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc new file mode 100644 index 000000000..f112bc2d8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/3.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +#include <algorithm> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// remove_if +void +test01() +{ + std::forward_list<int> fl ={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + fl.remove_if(std::bind2nd(std::less<int>(),5)); + + std::forward_list<int>::const_iterator pos = fl.cbegin(); + VERIFY(*pos == 5); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc new file mode 100644 index 000000000..6c09065e5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/4.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// unique +void +test01() +{ + std::forward_list<int> fl = {99, 5, 99, 6, -5, 666, 777, 888, + 42, 42, 42, 42, 42, 7, 0, 0, 0, 9, 9, 9}; + + fl.unique(); + + std::forward_list<int> fl2 = {99, 5, 99, 6, -5, 666, 777, 888, 42, 7, 0, 9}; + VERIFY(fl == fl2); +} + +// Test comparison predicate. +template<typename Num> + class Mod + { + public: + Mod(const Num & mod) + { + m = mod; + } + bool operator()(const Num i, const Num j) + { + return i%m == j%m; + } + private: + Num m; + }; + +// This test verifies the following: +// unique with predicate +void +test02() +{ + std::forward_list<int> fl = {99, 5, 99, 6, -5, 666, 777, 888, 42, 7, 0, 9}; + + fl.unique(Mod<int>(111)); + + std::forward_list<int> fl2 = {99, 5, 99, 6, -5, 666, 42, 7, 0, 9}; + VERIFY(fl == fl2); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc new file mode 100644 index 000000000..55d1634c4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/5.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// +void +test01() +{ + std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; + std::forward_list<double> b = {1.0, 2.0, 3.0, 4.0, 4.0, 5.0}; + + a.merge(std::move(b)); + + std::forward_list<double> r = {0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, + 4.0, 4.0, 4.0, 5.0}; + + VERIFY(a == r); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc new file mode 100644 index 000000000..082d2adbb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc @@ -0,0 +1,83 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +// Comparison functor. +template<typename Num> + class Comp + { + public: + Comp(const Num & num) + { + n = num; + } + bool operator()(const Num i, const Num j) + { + return (n * i) < (n * j); + } + private: + Num n; + }; + +// This test verifies the following: +// +void +test01() +{ + const unsigned int n = 13; + int order[][n] = { + { 0,1,2,3,4,5,6,7,8,9,10,11,12 }, + { 6,2,8,4,11,1,12,7,3,9,5,0,10 }, + { 12,11,10,9,8,7,6,5,4,3,2,1,0 }, + }; + std::forward_list<int> sorted(order[0], order[0] + n); + + for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i) + { + std::forward_list<int> head(order[i], order[i] + n); + + head.sort(); + + VERIFY(head == sorted); + } + + std::forward_list<int> reversed(order[2], order[2] + n); + for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i) + { + std::forward_list<int> head(order[i], order[i] + n); + + Comp<int> comp(-1); + head.sort( comp ); + + VERIFY(head == reversed); + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/7.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/7.cc new file mode 100644 index 000000000..fd71cb631 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/7.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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.3.n forward_list xxx [lib.forward_list.xxx] + +#include <forward_list> +#include <testsuite_hooks.h> + +#include <algorithm> + +bool test __attribute__((unused)) = true; + +// This test verifies the following: +// +void +test01() +{ + const unsigned int n = 13; + int order[n] = {0,1,2,3,4,5,6,7,8,9,10,11,12}; + + std::forward_list<int> fl(order, order + n); + + std::forward_list<int> fl2; + for (std::size_t i = 0; i < n; ++i) + fl2.push_front(order[i]); + + fl.reverse(); + + VERIFY(std::lexicographical_compare(fl.begin(), fl.end(), + fl2.begin(), fl2.end()) == false); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/operations/remove_freed.cc b/libstdc++-v3/testsuite/23_containers/forward_list/operations/remove_freed.cc new file mode 100644 index 000000000..5b9592092 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/operations/remove_freed.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-08-11 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <forward_list> +#include <testsuite_hooks.h> + +// 23.3.3.5 forward_list operations [forwardlist.ops] + +// Used to cause many Valgrind errors: LWG 526-type situation. +void test01() +{ + bool test __attribute__((unused)) = true; + + std::forward_list<int> fl1; + + fl1.push_front(1); + fl1.push_front(2); + fl1.push_front(3); + fl1.push_front(4); + fl1.push_front(1); + + fl1.remove(*fl1.begin()); + + VERIFY( std::distance(fl1.begin(), fl1.end()) == 3 ); + + auto it1 = fl1.begin(); + + VERIFY( *it1 == 4 ); + ++it1; + VERIFY( *it1 == 3 ); + ++it1; + VERIFY( *it1 == 2 ); + + std::forward_list<int> fl2; + + fl2.push_front(3); + fl2.push_front(3); + fl2.push_front(3); + fl2.push_front(3); + fl2.push_front(3); + + auto it2 = fl2.begin(); + ++it2; + ++it2; + + fl2.remove(*it2); + + VERIFY( std::distance(fl2.begin(), fl2.end()) == 0 ); + + std::forward_list<int> fl3; + + fl3.push_front(1); + fl3.push_front(2); + fl3.push_front(3); + fl3.push_front(3); + fl3.push_front(3); + + auto it3 = fl3.begin(); + ++it3; + ++it3; + + fl3.remove(*it3); + + VERIFY( std::distance(fl3.begin(), fl3.end()) == 2 ); + + it3 = fl3.begin(); + VERIFY( *it3 == 2 ); + ++it3; + VERIFY( *it3 == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc b/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc new file mode 100644 index 000000000..350b8286c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <forward_list> + +void +test01() +{ + std::forward_list<int> fl{1, 2, 3}; + std::begin(fl); + std::end(fl); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/citerators.cc new file mode 100644 index 000000000..86fa26e31 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/citerators.cc @@ -0,0 +1,41 @@ +// { 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 <forward_list> +#include <testsuite_containers.h> + +namespace __gnu_test +{ + template<> + struct populate<std::forward_list<int>, true> + { + populate(std::forward_list<int>& container) + { + container.push_front(1); + container.push_front(2); + } + }; +} + +int main() +{ + typedef std::forward_list<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc new file mode 100644 index 000000000..e87fa60c3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-error "no matching" "" { target *-*-* } 1206 } +// { dg-excess-errors "" } + +// Copyright (C) 2009, 2010 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 <forward_list> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + typedef std::forward_list<A> test_type; + test_type l; + l.assign(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor.cc new file mode 100644 index 000000000..407d8d169 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor.cc @@ -0,0 +1,27 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 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 <forward_list> + +void f() +{ + typedef std::forward_list<int> test_type; + test_type l(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc new file mode 100644 index 000000000..5da159c13 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-error "no matching" "" { target *-*-* } 1206 } +// { dg-excess-errors "" } + +// Copyright (C) 2009, 2010, 2011 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 <forward_list> + +void f() +{ + typedef std::forward_list<std::forward_list<int> > test_type; + test_type l(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc new file mode 100644 index 000000000..785fe5136 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-error "no matching" "" { target *-*-* } 1206 } +// { dg-excess-errors "" } + +// Copyright (C) 2009, 2010, 2011 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 <forward_list> +#include <utility> + +void f() +{ + typedef std::forward_list<std::forward_list<std::pair<char, char> > > test_type; + test_type l('a', 'b'); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc new file mode 100644 index 000000000..aabc8b8f7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-error "no matching" "" { target *-*-* } 1206 } +// { dg-excess-errors "" } + +// Copyright (C) 2009, 2010, 2011 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 <forward_list> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + typedef std::forward_list<A> test_type; + test_type l; + l.insert_after(l.begin(), 10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/basic.cc new file mode 100644 index 000000000..672daf840 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/basic.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <forward_list> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::forward_list<value_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..7d1764799 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/generation_prohibited.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <forward_list> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::forward_list<value_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..5c426c93c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/exception/propagation_consistent.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <forward_list> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::forward_list<value_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..d2d89772c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/1.cc @@ -0,0 +1,27 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <forward_list> + +// { dg-do compile } + +template class std::forward_list<int>; diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..f16650ae9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/3.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <forward_list> + +// { dg-do compile } + +// libstdc++/21770 +template class std::forward_list<int, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..11f15248f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/explicit_instantiation/4.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + + +// This file tests explicit instantiation of library containers + +#include <forward_list> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::forward_list<__gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/typedefs.cc new file mode 100644 index 000000000..3497b09de --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <forward_list> + +// Check container for required typedefs. +__gnu_test::types<std::forward_list<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/headers/array/std_c++0x_neg.cc b/libstdc++-v3/testsuite/23_containers/headers/array/std_c++0x_neg.cc new file mode 100644 index 000000000..e9317d7ed --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/array/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 2007, 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 <array> + +// { dg-error "upcoming ISO" "" { target *-*-* } 32 } + + + diff --git a/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc new file mode 100644 index 000000000..0eccdf4bb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <bitset> + +namespace std { + template <size_t N> class bitset; + + // 23.3.5.3 bitset operations: + template <size_t N> + bitset<N> operator&(const bitset<N>&, const bitset<N>&); + + template <size_t N> + bitset<N> operator|(const bitset<N>&, const bitset<N>&); + + template <size_t N> + bitset<N> operator^(const bitset<N>&, const bitset<N>&); + + template <class charT, class traits, size_t N> + basic_istream<charT, traits>& + operator>>(basic_istream<charT, traits>& is, bitset<N>& x); + + template <class charT, class traits, size_t N> + basic_ostream<charT, traits>& + operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc new file mode 100644 index 000000000..137ed6155 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <deque> + +namespace std { + template <class T, class Allocator> class deque; + + template <class T, class Allocator> + bool operator== (const deque<T,Allocator>& x, const deque<T,Allocator>& y); + + template <class T, class Allocator> + bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); + + template <class T, class Allocator> + bool operator!= (const deque<T,Allocator>& x, const deque<T,Allocator>& y); + + template <class T, class Allocator> + bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); + + template <class T, class Allocator> + bool operator>= (const deque<T,Allocator>& x, const deque<T,Allocator>& y); + + template <class T, class Allocator> + bool operator<= (const deque<T,Allocator>& x, const deque<T,Allocator>& y); + + template <class T, class Allocator> + void swap(deque<T,Allocator>& x, deque<T,Allocator>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc new file mode 100644 index 000000000..73cd9c5b5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc @@ -0,0 +1,53 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 2009, 2010 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 <forward_list> + +namespace std { + template <class T, class Allocator> class forward_list; + + template <class T, class Allocator> + bool operator==(const forward_list<T,Allocator>& x, + const forward_list<T,Allocator>&); + + template <class T, class Allocator> + bool operator< (const forward_list<T,Allocator>& x, + const forward_list<T,Allocator>&); + + template <class T, class Allocator> + bool operator!=(const forward_list<T,Allocator>& x, + const forward_list<T,Allocator>&); + + template <class T, class Allocator> + bool operator> (const forward_list<T,Allocator>& x, + const forward_list<T,Allocator>&); + + template <class T, class Allocator> + bool operator>=(const forward_list<T,Allocator>& x, + const forward_list<T,Allocator>&); + + template <class T, class Allocator> + bool operator<=(const forward_list<T,Allocator>& x, + const forward_list<T,Allocator>&); + + template <class T, class Allocator> + void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc new file mode 100644 index 000000000..7d44c7cd0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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> + +namespace std { + template <class T, class Allocator> class list; + + template <class T, class Allocator> + bool operator==(const list<T,Allocator>& x, const list<T,Allocator>&); + + template <class T, class Allocator> + bool operator< (const list<T,Allocator>& x, const list<T,Allocator>&); + + template <class T, class Allocator> + bool operator!=(const list<T,Allocator>& x, const list<T,Allocator>&); + + template <class T, class Allocator> + bool operator> (const list<T,Allocator>& x, const list<T,Allocator>&); + + template <class T, class Allocator> + bool operator>=(const list<T,Allocator>& x, const list<T,Allocator>&); + + template <class T, class Allocator> + bool operator<=(const list<T,Allocator>& x, const list<T,Allocator>&); + + template <class T, class Allocator> + void swap(list<T,Allocator>& x, list<T,Allocator>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc new file mode 100644 index 000000000..0fc977c9d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc @@ -0,0 +1,71 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <map> + +namespace std { + template <class Key, class T, class Compare, class Allocator> + class map; + template <class Key, class T, class Compare, class Allocator> + bool operator==(const map<Key,T,Compare,Allocator>& x, + const map<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator< (const map<Key,T,Compare,Allocator>& x, + const map<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator!=(const map<Key,T,Compare,Allocator>& x, + const map<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator> (const map<Key,T,Compare,Allocator>& x, + const map<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator>=(const map<Key,T,Compare,Allocator>& x, + const map<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator<=(const map<Key,T,Compare,Allocator>& x, + const map<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + void swap(map<Key,T,Compare,Allocator>& x, + map<Key,T,Compare,Allocator>& y); + + template <class Key, class T, class Compare, class Allocator> + class multimap; + template <class Key, class T, class Compare, class Allocator> + bool operator==(const multimap<Key,T,Compare,Allocator>& x, + const multimap<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator< (const multimap<Key,T,Compare,Allocator>& x, + const multimap<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator!=(const multimap<Key,T,Compare,Allocator>& x, + const multimap<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator> (const multimap<Key,T,Compare,Allocator>& x, + const multimap<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator>=(const multimap<Key,T,Compare,Allocator>& x, + const multimap<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + bool operator<=(const multimap<Key,T,Compare,Allocator>& x, + const multimap<Key,T,Compare,Allocator>& y); + template <class Key, class T, class Compare, class Allocator> + void swap(multimap<Key,T,Compare,Allocator>& x, + multimap<Key,T,Compare,Allocator>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc new file mode 100644 index 000000000..ae2bb0e94 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc @@ -0,0 +1,50 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <queue> + +namespace std { + template <class T, class Container> class queue; + template <class T, class Container> + bool operator==(const queue<T, Container>& x, + const queue<T, Container>& y); + + template <class T, class Container> + bool operator< (const queue<T, Container>& x, + const queue<T, Container>& y); + + template <class T, class Container> + bool operator!=(const queue<T, Container>& x, + const queue<T, Container>& y); + + template <class T, class Container> + bool operator> (const queue<T, Container>& x, + const queue<T, Container>& y); + + template <class T, class Container> + bool operator>=(const queue<T, Container>& x, + const queue<T, Container>& y); + + template <class T, class Container> + bool operator<=(const queue<T, Container>& x, + const queue<T, Container>& y); + + template <class T, class Container, class Compare> + class priority_queue; +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc new file mode 100644 index 000000000..94ae348f6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc @@ -0,0 +1,85 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <set> + +namespace std { + template <class Key, class Compare, class Allocator> + class set; + + template <class Key, class Compare, class Allocator> + bool operator==(const set<Key,Compare,Allocator>& x, + const set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator< (const set<Key,Compare,Allocator>& x, + const set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator!=(const set<Key,Compare,Allocator>& x, + const set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator> (const set<Key,Compare,Allocator>& x, + const set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator>=(const set<Key,Compare,Allocator>& x, + const set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator<=(const set<Key,Compare,Allocator>& x, + const set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + void swap(set<Key,Compare,Allocator>& x, + set<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + class multiset; + + template <class Key, class Compare, class Allocator> + bool operator==(const multiset<Key,Compare,Allocator>& x, + const multiset<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator< (const multiset<Key,Compare,Allocator>& x, + const multiset<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator!=(const multiset<Key,Compare,Allocator>& x, + const multiset<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator> (const multiset<Key,Compare,Allocator>& x, + const multiset<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator>=(const multiset<Key,Compare,Allocator>& x, + const multiset<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + bool operator<=(const multiset<Key,Compare,Allocator>& x, + const multiset<Key,Compare,Allocator>& y); + + template <class Key, class Compare, class Allocator> + void swap(multiset<Key,Compare,Allocator>& x, + multiset<Key,Compare,Allocator>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc new file mode 100644 index 000000000..1f7b5eea8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc @@ -0,0 +1,48 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <stack> + +namespace std { + template <class T, class Container> class stack; + + template <class T, class Container> + bool operator==(const stack<T, Container>& x, + const stack<T, Container>& y); + + template <class T, class Container> + bool operator< (const stack<T, Container>& x, + const stack<T, Container>& y); + + template <class T, class Container> + bool operator!=(const stack<T, Container>& x, + const stack<T, Container>& y); + + template <class T, class Container> + bool operator> (const stack<T, Container>& x, + const stack<T, Container>& y); + + template <class T, class Container> + bool operator>=(const stack<T, Container>& x, + const stack<T, Container>& y); + + template <class T, class Container> + bool operator<=(const stack<T, Container>& x, + const stack<T, Container>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/tuple/std_c++0x_neg.cc b/libstdc++-v3/testsuite/23_containers/headers/tuple/std_c++0x_neg.cc new file mode 100644 index 000000000..0a2e073a5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/tuple/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 2007, 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 <tuple> + +// { dg-error "upcoming ISO" "" { target *-*-* } 32 } + + + diff --git a/libstdc++-v3/testsuite/23_containers/headers/tuple/types_std_c++0x.cc b/libstdc++-v3/testsuite/23_containers/headers/tuple/types_std_c++0x.cc new file mode 100644 index 000000000..774594570 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/tuple/types_std_c++0x.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <tuple> + +namespace gnu +{ + using std::ignore; +} diff --git a/libstdc++-v3/testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc b/libstdc++-v3/testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc new file mode 100644 index 000000000..0b32304ca --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 2007, 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 <unordered_map> + +// { dg-error "upcoming ISO" "" { target *-*-* } 32 } + + + diff --git a/libstdc++-v3/testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc b/libstdc++-v3/testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc new file mode 100644 index 000000000..bc6963c80 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 2007, 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 <unordered_set> + +// { dg-error "upcoming ISO" "" { target *-*-* } 32 } + + + diff --git a/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc new file mode 100644 index 000000000..e543e8fd3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc @@ -0,0 +1,81 @@ +// { dg-do compile } +// { dg-require-normal-mode "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <vector> + +namespace std { + template <class T, class Allocator> class vector; + + template <class T, class Allocator> + bool operator==(const vector<T,Allocator>& x, + const vector<T,Allocator>& y); + + template <class T, class Allocator> + bool operator< (const vector<T,Allocator>& x, + const vector<T,Allocator>& y); + + template <class T, class Allocator> + bool operator!=(const vector<T,Allocator>& x, + const vector<T,Allocator>& y); + + template <class T, class Allocator> + bool operator> (const vector<T,Allocator>& x, + const vector<T,Allocator>& y); + + template <class T, class Allocator> + bool operator>=(const vector<T,Allocator>& x, + const vector<T,Allocator>& y); + + template <class T, class Allocator> + bool operator<=(const vector<T,Allocator>& x, + const vector<T,Allocator>& y); + + template <class T, class Allocator> + void swap(vector<T,Allocator>& x, vector<T,Allocator>& y); + + template <class Allocator> class vector<bool,Allocator>; + + template <class Allocator> + bool operator==(const vector<bool,Allocator>& x, + const vector<bool,Allocator>& y); + + template <class Allocator> + bool operator< (const vector<bool,Allocator>& x, + const vector<bool,Allocator>& y); + + template <class Allocator> + bool operator!=(const vector<bool,Allocator>& x, + const vector<bool,Allocator>& y); + + template <class Allocator> + bool operator> (const vector<bool,Allocator>& x, + const vector<bool,Allocator>& y); + + template <class Allocator> + bool operator>=(const vector<bool,Allocator>& x, + const vector<bool,Allocator>& y); + + template <class Allocator> + bool operator<=(const vector<bool,Allocator>& x, + const vector<bool,Allocator>& y); + + template <class Allocator> + void swap(vector<bool,Allocator>& x, vector<bool,Allocator>& y); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/14340.cc b/libstdc++-v3/testsuite/23_containers/list/14340.cc new file mode 100644 index 000000000..5606ff042 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/14340.cc @@ -0,0 +1,34 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <list> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::list<int> list_type; + __gnu_test::conversion<list_type>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/18604.cc b/libstdc++-v3/testsuite/23_containers/list/18604.cc new file mode 100644 index 000000000..398d0f6cd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/18604.cc @@ -0,0 +1,42 @@ +// 2005-05-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include <list> diff --git a/libstdc++-v3/testsuite/23_containers/list/23781_neg.cc b/libstdc++-v3/testsuite/23_containers/list/23781_neg.cc new file mode 100644 index 000000000..7b291df79 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/23781_neg.cc @@ -0,0 +1,29 @@ +// 2005-09-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2009, 2010 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/>. +// + +// { dg-do compile } + +// libstdc++/23781 +#include <list> +#include <cstddef> + +typedef std::list<int> list_type; +list_type::iterator it = NULL; // { dg-error "conversion" } +list_type::const_iterator cit = NULL; // { dg-error "conversion" } diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc new file mode 100644 index 000000000..3b0e8dc72 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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() +{ + capacity01<std::list<int> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/1.h b/libstdc++-v3/testsuite/23_containers/list/capacity/1.h new file mode 100644 index 000000000..408e0786c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/1.h @@ -0,0 +1,61 @@ +// Copyright (C) 2001, 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.2 list capacity [lib.list.capacity] + +#include <testsuite_hooks.h> + +// This test verifies the following. +// +// 23.2.2 bool empty() const +// 23.2.2 size_type size() const +// 23.2.2 iterator begin() +// 23.2.2 iterator end() +// 23.2.2.3 void push_back(const T&) +// 23.2.2 size_type max_size() const +// 23.2.2.2 void resize(size_type s, T c = T()) +// +template<typename _Tp> +void +capacity01() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + typedef typename list_type::iterator iterator_type; + + list_type list0101; + VERIFY(list0101.empty()); + VERIFY(list0101.size() == 0); + + list0101.push_back(1); + VERIFY(!list0101.empty()); + VERIFY(list0101.size() == 1); + + list0101.resize(3, 2); + VERIFY(!list0101.empty()); + VERIFY(list0101.size() == 3); + + iterator_type i = list0101.begin(); + VERIFY(*i == 1); ++i; + VERIFY(*i == 2); ++i; + VERIFY(*i == 2); ++i; + VERIFY(i == list0101.end()); + + list0101.resize(0); + VERIFY(list0101.empty()); + VERIFY(list0101.size() == 0); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/list/capacity/29134.cc new file mode 100644 index 000000000..d8c88b526 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/29134.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2006, 2007, 2008, 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.2 list capacity [lib.list.capacity] + +#include <list> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::list<int> list_type; + list_type l; + +#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE + using std::_List_node; +#else + using std::_GLIBCXX_STD_C::_List_node; +#endif + + VERIFY( l.max_size() == std::allocator<_List_node<int> >().max_size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc b/libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc new file mode 100644 index 000000000..06424c0a8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<__gnu_test::NonCopyConstructible> l; + VERIFY( std::distance(l.begin(), l.end()) == 0 ); + + l.resize(1000); + VERIFY( std::distance(l.begin(), l.end()) == 1000 ); + for(auto it = l.begin(); it != l.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc new file mode 100644 index 000000000..31dacb592 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc @@ -0,0 +1,29 @@ +// 2004-07-26 Matt Austern <austern@apple.com> +// +// Copyright (C) 2003, 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 "check_construct_destroy.h" +#include <list> + +int main() +{ + typedef __gnu_test::tracker_allocator<int> allocator_type; + construct_destroy<std::list<int, allocator_type> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h new file mode 100644 index 000000000..14da42dc8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h @@ -0,0 +1,79 @@ +// 2004-07-26 Matt Austern <austern@apple.com> +// +// Copyright (C) 2003, 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 <iterator> +#include <testsuite_allocator.h> + +template<typename _Tp> +bool +construct_destroy() +{ + typedef _Tp list_type; + typedef typename list_type::iterator iterator_type; + + using namespace __gnu_test; + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + list_type c; + ok = check_construct_destroy("empty container", 0, 0) && ok; + } + ok = check_construct_destroy("empty container", 0, 0) && ok; + + + tracker_allocator_counter::reset(); + { + list_type c(arr10, arr10 + 10); + ok = check_construct_destroy("Construct from range", 10, 0) && ok; + } + ok = check_construct_destroy("Construct from range", 10, 10) && ok; + + { + list_type c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(c.begin(), arr10[0]); + ok = check_construct_destroy("Insert element", 1, 0) && ok; + } + ok = check_construct_destroy("Insert element", 1, 11) && ok; + + { + list_type c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + iterator_type i5 = c.begin(); + std::advance(i5, 5); + c.insert(i5, arr10, arr10+3); + ok = check_construct_destroy("Insert short range", 3, 0) && ok; + } + ok = check_construct_destroy("Insert short range", 3, 13) && ok; + + { + list_type c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + iterator_type i7 = c.begin(); + std::advance(i7, 5); + c.insert(i7, arr10, arr10+10); + ok = check_construct_destroy("Insert long range", 10, 0) && ok; + } + ok = check_construct_destroy("Insert long range", 10, 20) && ok; + + return ok ? 0 : 1; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/1.cc b/libstdc++-v3/testsuite/23_containers/list/cons/1.cc new file mode 100644 index 000000000..da469ebb1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2001, 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() +{ + cons01<std::list< A<B> > >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/1.h b/libstdc++-v3/testsuite/23_containers/list/cons/1.h new file mode 100644 index 000000000..2aa48be91 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/1.h @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// A nontrivial type. +template<typename T> + struct A { }; + +// Another nontrivial type +struct B { }; + +// Default constructor, basic properties +// +// This test verifies the following. +// 23.2.2.1 explicit list(const a& = Allocator()) +// 23.1 (7) iterator behaviour of empty containers +// 23.2.2 iterator begin() +// 23.2.2 iterator end() +// 23.2.2 size_type size() const +// 23.2.2 existence of required typedefs +// +template<typename _Tp> +void +cons01() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + + list_type list0101; + VERIFY(list0101.begin() == list0101.end()); + VERIFY(list0101.size() == 0); + + // check type definitions -- will fail compile if missing + typedef typename list_type::reference reference; + typedef typename list_type::const_reference const_reference; + typedef typename list_type::iterator iterator; + typedef typename list_type::const_iterator const_iterator; + typedef typename list_type::size_type size_type; + typedef typename list_type::difference_type difference_type; + typedef typename list_type::value_type value_type; + typedef typename list_type::allocator_type allocator_type; + typedef typename list_type::pointer pointer; + typedef typename list_type::const_pointer const_pointer; + typedef typename list_type::reverse_iterator reverse_iterator; + typedef typename list_type::const_reverse_iterator const_reverse_iterator; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/2.cc b/libstdc++-v3/testsuite/23_containers/list/cons/2.cc new file mode 100644 index 000000000..86c59f383 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/2.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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() +{ + cons021<std::list<int> >(); + cons022<std::list< A<B> > >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/2.h b/libstdc++-v3/testsuite/23_containers/list/cons/2.h new file mode 100644 index 000000000..eb32896e7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/2.h @@ -0,0 +1,77 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// A nontrivial type. +template<typename T> + struct A { }; + +// Another nontrivial type +struct B { }; + +// Fill constructor +// +// This test verifies the following. +// 23.2.2.1 explicit list(size_type n, const T& v = T(), const a& = Allocator()) +// 23.2.2 const_iterator begin() const +// 23.2.2 const_iterator end() const +// 23.2.2 size_type size() const +// +template<typename _Tp> +void +cons021() +{ + bool test __attribute__((unused)) = true; + const std::size_t LIST_SIZE = 5; + const int INIT_VALUE = 7; + std::size_t count; + + typedef _Tp list_type; + typedef typename list_type::const_iterator const_iterator; + const_iterator i; + + // default value + list_type list0202(LIST_SIZE); + for (i = list0202.begin(), count = 0; + i != list0202.end(); + ++i, ++count) + VERIFY(*i == 0); + VERIFY(count == LIST_SIZE); + VERIFY(list0202.size() == LIST_SIZE); + + // explicit value + list_type list0203(LIST_SIZE, INIT_VALUE); + for (i = list0203.begin(), count = 0; + i != list0203.end(); + ++i, ++count) + VERIFY(*i == INIT_VALUE); + VERIFY(count == LIST_SIZE); + VERIFY(list0203.size() == LIST_SIZE); +} + +template<typename _Tp> +void +cons022() +{ + // nontrivial value_type + typedef _Tp list_type; + const std::size_t LIST_SIZE = 5; + list_type list0201(LIST_SIZE); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/3.cc b/libstdc++-v3/testsuite/23_containers/list/cons/3.cc new file mode 100644 index 000000000..f373cc05d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/3.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2001, 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() +{ + cons03<std::list<C> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/3.h b/libstdc++-v3/testsuite/23_containers/list/cons/3.h new file mode 100644 index 000000000..983c24ca8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/3.h @@ -0,0 +1,48 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// A nontrivial type convertible from an int +struct C +{ + C(int i) : i_(i) { } + bool operator==(const C& rhs) { return i_ == rhs.i_; } + int i_; +}; + +// Fill constructor disguised as a range constructor +template<typename _Tp> +void +cons03() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + + const std::size_t LIST_SIZE = 5; + const int INIT_VALUE = 7; + std::size_t count = 0; + list_type list0204(LIST_SIZE, INIT_VALUE); + iterator i = list0204.begin(); + for (; i != list0204.end(); ++i, ++count) + VERIFY(*i == INIT_VALUE); + VERIFY(count == LIST_SIZE); + VERIFY(list0204.size() == LIST_SIZE); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/4.cc b/libstdc++-v3/testsuite/23_containers/list/cons/4.cc new file mode 100644 index 000000000..d6b58be04 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/4.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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 "4.h" +#include <list> + +int main() +{ + cons04<std::list<int> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/4.h b/libstdc++-v3/testsuite/23_containers/list/cons/4.h new file mode 100644 index 000000000..bf2e51c13 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/4.h @@ -0,0 +1,61 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// Range constructor +// +// This test verifies the following. +// 23.2.2.1 template list(InputIterator f, InputIterator l, +// const Allocator& a = Allocator()) +// 23.2.2 const_iterator begin() const +// 23.2.2 const_iterator end() const +// 23.2.2 size_type size() const +// +template<typename _Tp> +void +cons04() +{ + bool test __attribute__((unused)) = true; + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const std::size_t N = sizeof(A) / sizeof(int); + std::size_t count; + + typedef _Tp list_type; + typedef typename list_type::const_iterator const_iterator; + const_iterator i; + + // construct from a dissimilar range + list_type list0301(A, A + N); + for (i = list0301.begin(), count = 0; + i != list0301.end(); + ++i, ++count) + VERIFY(*i == A[count]); + VERIFY(count == N); + VERIFY(list0301.size() == N); + + // construct from a similar range + list_type list0302(list0301.begin(), list0301.end()); + for (i = list0302.begin(), count = 0; + i != list0302.end(); + ++i, ++count) + VERIFY(*i == A[count]); + VERIFY(count == N); + VERIFY(list0302.size() == N); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/5.cc b/libstdc++-v3/testsuite/23_containers/list/cons/5.cc new file mode 100644 index 000000000..de86dccd6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/5.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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 "5.h" +#include <list> + +int main() +{ + cons05<std::list<int> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/5.h b/libstdc++-v3/testsuite/23_containers/list/cons/5.h new file mode 100644 index 000000000..5c273a322 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/5.h @@ -0,0 +1,51 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// Copy constructor +// +// This test verifies the following. +// 23.2.2.1 list(const list& x) +// 23.2.2 reverse_iterator rbegin() +// 23.2.2 reverse_iterator rend() +// 23.2.2 size_type size() const +// +template<typename _Tp> +void +cons05() +{ + bool test __attribute__((unused)) = true; + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const std::size_t N = sizeof(A) / sizeof(int); + int count; + + typedef _Tp list_type; + typedef typename list_type::reverse_iterator reverse_iterator; + reverse_iterator i; + list_type list0401(A, A + N); + + list_type list0402(list0401); + for (i = list0401.rbegin(), count = N - 1; + i != list0401.rend(); + ++i, --count) + VERIFY(*i == A[count]); + VERIFY(count == -1); + VERIFY(list0401.size() == N); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/6.cc b/libstdc++-v3/testsuite/23_containers/list/cons/6.cc new file mode 100644 index 000000000..c1a2baedc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/6.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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 "6.h" +#include <list> + +int main() +{ + cons06<std::list<int> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/6.h b/libstdc++-v3/testsuite/23_containers/list/cons/6.h new file mode 100644 index 000000000..b247e5563 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/6.h @@ -0,0 +1,64 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// Range assign +// +// This test verifies the following. +// 23.2.2.1 void assign(InputIterator f, InputIterator l) +// 23.2.2 const_iterator begin() const +// 23.2.2 const_iterator end() const +// 23.2.2 size_type size() const +// +template<typename _Tp> +void +cons06() +{ + bool test __attribute__((unused)) = true; + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int B[] = {101, 102, 103, 104, 105}; + const std::size_t N = sizeof(A) / sizeof(int); + const std::size_t M = sizeof(B) / sizeof(int); + std::size_t count; + + typedef _Tp list_type; + typedef typename list_type::const_iterator const_iterator; + const_iterator i; + + list_type list0501; + + // make it bigger + list0501.assign(A, A + N); + for (i = list0501.begin(), count = 0; + i != list0501.end(); + ++i, ++count) + VERIFY(*i == A[count]); + VERIFY(count == N); + VERIFY(list0501.size() == N); + + // make it smaller + list0501.assign(B, B + M); + for (i = list0501.begin(), count = 0; + i != list0501.end(); + ++i, ++count) + VERIFY(*i == B[count]); + VERIFY(count == M); + VERIFY(list0501.size() == M); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/7.cc b/libstdc++-v3/testsuite/23_containers/list/cons/7.cc new file mode 100644 index 000000000..0f3de3c67 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/7.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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 "7.h" +#include <list> + +int main() +{ + cons07<std::list<int> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/7.h b/libstdc++-v3/testsuite/23_containers/list/cons/7.h new file mode 100644 index 000000000..1ebd7a5cf --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/7.h @@ -0,0 +1,65 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// Fill assign +// +// This test verifies the following. +// 23.2.2.1 void assign(size_type n, const T& v) +// 23.2.2 const_iterator begin() const +// 23.2.2 const_iterator end() const +// 23.2.2 size_type size() const +// +template<typename _Tp> +void +cons07() +{ + bool test __attribute__((unused)) = true; + const std::size_t BIG_LIST_SIZE = 11; + const int BIG_INIT_VALUE = 7; + const std::size_t SMALL_LIST_SIZE = 5; + const int SMALL_INIT_VALUE = 17; + std::size_t count; + + typedef _Tp list_type; + typedef typename list_type::const_iterator const_iterator; + const_iterator i; + + list_type list0601; + VERIFY(list0601.size() == 0); + + // make it bigger + list0601.assign(BIG_LIST_SIZE, BIG_INIT_VALUE); + for (i = list0601.begin(), count = 0; + i != list0601.end(); + ++i, ++count) + VERIFY(*i == BIG_INIT_VALUE); + VERIFY(count == BIG_LIST_SIZE); + VERIFY(list0601.size() == BIG_LIST_SIZE); + + // make it shrink + list0601.assign(SMALL_LIST_SIZE, SMALL_INIT_VALUE); + for (i = list0601.begin(), count = 0; + i != list0601.end(); + ++i, ++count) + VERIFY(*i == SMALL_INIT_VALUE); + VERIFY(count == SMALL_LIST_SIZE); + VERIFY(list0601.size() == SMALL_LIST_SIZE); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/8.cc b/libstdc++-v3/testsuite/23_containers/list/cons/8.cc new file mode 100644 index 000000000..16d888b44 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/8.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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 "8.h" +#include <list> + +int main() +{ + cons08<std::list<C> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/8.h b/libstdc++-v3/testsuite/23_containers/list/cons/8.h new file mode 100644 index 000000000..4aed16b81 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/8.h @@ -0,0 +1,51 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// A nontrivial type convertible from an int +struct C +{ + C(int i) : i_(i) { } + bool operator==(const C& rhs) { return i_ == rhs.i_; } + int i_; +}; + +// Fill Assignment disguised as a Range Assignment +template<typename _Tp> +void +cons08() +{ + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + bool test __attribute__((unused)) = true; + const std::size_t LIST_SIZE = 5; + const int INIT_VALUE = 7; + std::size_t count = 0; + + list_type list0604; + VERIFY(list0604.size() == 0); + + list0604.assign(LIST_SIZE, INIT_VALUE); + iterator i = list0604.begin(); + for (; i != list0604.end(); ++i, ++count) + VERIFY(*i == INIT_VALUE); + VERIFY(count == LIST_SIZE); + VERIFY(list0604.size() == LIST_SIZE); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/9.cc b/libstdc++-v3/testsuite/23_containers/list/cons/9.cc new file mode 100644 index 000000000..908454453 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/9.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2001, 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 "9.h" +#include <list> + +int main() +{ + cons09<std::list<int> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/9.h b/libstdc++-v3/testsuite/23_containers/list/cons/9.h new file mode 100644 index 000000000..90c3fd054 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/9.h @@ -0,0 +1,59 @@ +// Copyright (C) 2001, 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.1 list constructors, copy, and assignment + +#include <testsuite_hooks.h> + +// Assignment operator +// +// This test verifies the following. +// 23.2.2 operator=(const list& x) +// 23.2.2 iterator begin() +// 23.2.2 iterator end() +// 23.2.2 size_type size() const +// 23.2.2 bool operator==(const list& x, const list& y) +// +template<typename _Tp> +void +cons09() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + + const int A[] = {701, 702, 703, 704, 705}; + const std::size_t N = sizeof(A) / sizeof(int); + std::size_t count; + + iterator i; + + list_type list0701(A, A + N); + VERIFY(list0701.size() == N); + + list_type list0702; + VERIFY(list0702.size() == 0); + + list0702 = list0701; + VERIFY(list0702.size() == N); + for (i = list0702.begin(), count = 0; + i != list0702.end(); + ++i, ++count) + VERIFY(*i == A[count]); + VERIFY(count == N); + VERIFY(list0702 == list0701); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc new file mode 100644 index 000000000..cb186d321 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2004, 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 "clear_allocator.h" +#include <list> + +int main() +{ + typedef std::list<int, clear_alloc<int> > list_type; + Check_Container<list_type>(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h new file mode 100644 index 000000000..3a53751c9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h @@ -0,0 +1,78 @@ +// Copyright (C) 2004, 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 <ext/new_allocator.h> + +using namespace std; +using __gnu_cxx::new_allocator; + +template<typename T> + class clear_alloc : public new_allocator<T> + { + public: + + template <typename T1> + struct rebind + { typedef clear_alloc<T1> other; }; + + virtual void clear() throw() + { } + + clear_alloc() throw() + { } + + clear_alloc(clear_alloc const&) throw() : new_allocator<T>() + { } + + template<typename T1> + clear_alloc(clear_alloc<T1> const&) throw() + { } + + virtual ~clear_alloc() throw() + { this->clear(); } + + T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0) + { + this->clear(); + return new_allocator<T>::allocate(n, hint); + } + + void deallocate(T *ptr, typename new_allocator<T>::size_type n) + { + this->clear(); + new_allocator<T>::deallocate(ptr, n); + } + }; + +template<typename Container> + void Check_Container() + { + Container* pic = new Container; + int x = 230; + + while (x--) + { + pic->push_back(x); + } + + pic->get_allocator(); + + // The following has led to infinite recursions or cores. + pic->clear(); + + delete pic; + } diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc new file mode 100644 index 000000000..f59f520f9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<__gnu_test::NonCopyConstructible> l(1000); + VERIFY( std::distance(l.begin(), l.end()) == 1000 ); + for(auto it = l.begin(); it != l.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/list/cons/moveable.cc new file mode 100644 index 000000000..fbe06634e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/moveable.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 "moveable.h" +#include <list> + +int main() +{ + test_moveable<std::list<int> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/moveable.h b/libstdc++-v3/testsuite/23_containers/list/cons/moveable.h new file mode 100644 index 000000000..1f11d6221 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/moveable.h @@ -0,0 +1,41 @@ +// 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/>. + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on list (via swap). If the implementation changed +// this test may begin to fail. + +#include <utility> +#include <testsuite_hooks.h> + +template<typename _Tp> + void + test_moveable() + { + bool test __attribute__((unused)) = true; + + typedef _Tp list_type; + + list_type a,b; + a.push_back(1); + b = std::move(a); + VERIFY( b.size() == 1 && *b.begin() == 1 && a.size() == 0 ); + + list_type c(std::move(b)); + VERIFY( c.size() == 1 && *c.begin() == 1 ); + VERIFY( b.size() == 0 ); + } diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/assign1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/assign1_neg.cc new file mode 100644 index 000000000..e7b0e5cfe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/assign1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign1<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/assign2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/assign2_neg.cc new file mode 100644 index 000000000..1bd6c2f90 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/assign2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign2<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/assign3_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/assign3_neg.cc new file mode 100644 index 000000000..7a40d3189 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/assign3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign3<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/assign4_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/assign4_neg.cc new file mode 100644 index 000000000..bde7b923e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/assign4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign1<__gnu_debug::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/construct1_neg.cc new file mode 100644 index 000000000..cbd045571 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/construct2_neg.cc new file mode 100644 index 000000000..40fdf43b8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/construct3_neg.cc new file mode 100644 index 000000000..5000f5a07 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/construct4_neg.cc new file mode 100644 index 000000000..29843ea43 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/insert1_neg.cc new file mode 100644 index 000000000..aa35b46cf --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/insert2_neg.cc new file mode 100644 index 000000000..dc84fdd58 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/insert3_neg.cc new file mode 100644 index 000000000..aa4910838 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/list/debug/insert4_neg.cc new file mode 100644 index 000000000..ade280688 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/list> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::list<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/1.cc new file mode 100644 index 000000000..7198e2402 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/1.cc @@ -0,0 +1,59 @@ +// List iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +// Assignment +void test01() +{ + using std::advance; + + bool test __attribute__((unused)) = true; + + typedef __gnu_debug::list<int> list_type; + list_type v1; + list_type v2; + + v1.push_front(17); + + list_type::iterator start = v1.begin(); + list_type::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + finish = v1.end(); + v1.assign(v2.begin(), v2.end()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + finish = v1.end(); + v1.assign(17, 42); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/2.cc new file mode 100644 index 000000000..5872936bb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/2.cc @@ -0,0 +1,55 @@ +// List iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +// Resize +void test02() +{ + using std::advance; + + bool test __attribute__((unused)) = true; + + typedef __gnu_debug::list<int> list_type; + + list_type v(10, 17); + + list_type::iterator before = v.begin(); + advance(before, 6); + list_type::iterator at = before; + advance(at, 1); + list_type::iterator after = at; + advance(after, 1); + list_type::iterator finish = v.end(); + + // Shrink + v.resize(7); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/3.cc b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/3.cc new file mode 100644 index 000000000..0d4844793 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/3.cc @@ -0,0 +1,77 @@ +// List iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +// Erase +void test03() +{ + using std::advance; + + bool test __attribute__((unused)) = true; + typedef __gnu_debug::list<int> list_type; + + list_type v(20, 42); + + // Single element erase (middle) + list_type::iterator before = v.begin(); + list_type::iterator at = before; + advance(at, 3); + list_type::iterator after = at; + at = v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Single element erase (end) + before = v.begin(); + at = before; + after = at; + ++after; + at = v.erase(at); + VERIFY(before._M_singular()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 3); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + list_type::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/4.cc new file mode 100644 index 000000000..a5c9219a2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/debug/invalidation/4.cc @@ -0,0 +1,55 @@ +// List iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/list> +#include <iterator> +#include <testsuite_hooks.h> + +// Splice +void test04() +{ + using std::advance; + + bool test __attribute__((unused)) = true; + + typedef __gnu_debug::list<int> list_type; + + list_type l1(10, 17); + list_type l2(10, 42); + + list_type::iterator start2 = l2.begin(); + list_type::iterator end2 = start2; + advance(end2, 5); + list_type::iterator after2 = end2; + advance(after2, 2); + + l1.splice(l1.begin(), l2, start2, end2); + VERIFY(start2._M_dereferenceable()); + VERIFY(end2._M_dereferenceable()); + VERIFY(after2._M_dereferenceable()); + VERIFY(start2._M_attached_to(&l1)); + VERIFY(end2._M_attached_to(&l2)); + VERIFY(after2._M_attached_to(&l2)); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/init-list.cc b/libstdc++-v3/testsuite/23_containers/list/init-list.cc new file mode 100644 index 000000000..db6bc3b69 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/init-list.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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 "init-list.h" +#include <list> + +int main() +{ + typedef int value_type; + typedef __gnu_test::tracker_allocator<int> allocator_type; + typedef std::list<value_type, allocator_type> list_type; + init_list<list_type>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/init-list.h b/libstdc++-v3/testsuite/23_containers/list/init-list.h new file mode 100644 index 000000000..a391ffdad --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/init-list.h @@ -0,0 +1,65 @@ +// Copyright (C) 2008, 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 <testsuite_allocator.h> + +template<typename _Tp> +bool +init_list() +{ + using namespace __gnu_test; + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + list_type c({ 2, 4, 1 }); + ok = check_construct_destroy("Construct from init-list", 3, 0) && ok; + iterator i = c.begin(); + ok &= (*i++ == 2); + ok &= (*i++ == 4); + } + ok = check_construct_destroy("Construct from init-list", 3, 3) && ok; + + { + list_type c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + iterator i = c.begin(); + ++i; ++i; ++i; ++i; ++i; ++i; ++i; + c.insert(i, { 234, 42, 1 }); + ok = check_construct_destroy("Insert init-list", 3, 0) && ok; + ok &= (*--i == 1); + ok &= (*--i == 42); + } + ok = check_construct_destroy("Insert init-list", 3, 13) && ok; + + { + list_type c; + tracker_allocator_counter::reset(); + c = { 13, 0, 42 }; + ok = check_construct_destroy("Assign init-list", 3, 0) && ok; + iterator i = c.begin(); + ok &= (*i++ == 13); + } + ok = check_construct_destroy("Assign init-list", 3, 3) && ok; + + return ok ? 0 : 1; +} 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 ); +} 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 000000000..48c7d908c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/1.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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() +{ + operations01<std::list<int> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/1.h b/libstdc++-v3/testsuite/23_containers/list/operations/1.h new file mode 100644 index 000000000..601c5e772 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/1.h @@ -0,0 +1,68 @@ +// Copyright (C) 2001, 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.4 list operations [lib.list.ops] + +#include <testsuite_hooks.h> + +// splice(p, x) + remove + reverse +template<typename _Tp> +void +operations01() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + + 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); + + list_type list0101(A, A + N); + list_type list0102(B, B + M); + 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()); +} 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 000000000..7cd576220 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/2.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2001, 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() +{ + operations02<std::list<int> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/2.h b/libstdc++-v3/testsuite/23_containers/list/operations/2.h new file mode 100644 index 000000000..6db3333bd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/2.h @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 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.4 list operations [lib.list.ops] + +#include <testsuite_hooks.h> + +// splice(p, x, i) + remove_if + operator== +template<typename _Tp> +void +operations02() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + + 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); + list_type list0201(A, A + N); + list_type list0202(A, A + N); + list_type list0203(B, B + N); + list_type list0204(C, C + N); + 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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/2_c++0x.cc b/libstdc++-v3/testsuite/23_containers/list/operations/2_c++0x.cc new file mode 100644 index 000000000..6d744a015 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/2_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 "2.h" +#include <list> + +int main() +{ + operations02<std::list<int> >(); + 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 000000000..1ed46b21d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/3.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2001, 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(void) +{ + operations03<std::list<int> >(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/3.h b/libstdc++-v3/testsuite/23_containers/list/operations/3.h new file mode 100644 index 000000000..9181e7ea9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/3.h @@ -0,0 +1,68 @@ +// Copyright (C) 2001, 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.4 list operations [lib.list.ops] + +#include <testsuite_hooks.h> + +// splice(p, x, f, l) + sort + merge + unique +template<typename _Tp> +void +operations03() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + typedef typename list_type::iterator iterator; + + 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); + + list_type list0301(A, A + N); + list_type list0302(B, B + M); + list_type list0303(C, C + P); + list_type list0304(D, D + Q); + list_type list0305(E, E + R); + list_type list0306(F, F + R); + iterator p = list0301.begin(); + 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); +} 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 000000000..2442f9601 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/35969.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2008, 2009, 2010 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.4 list operations [lib.list.ops] + +// NB: This issue affected only debug-mode. + +#include <list> +#include <functional> + +// libstdc++/35969 +void test01() +{ + { + std::list<int> list1; + std::list<int> list2; + + for(int i = 0; i < 10; ++i) + { + list1.push_back(i); + list2.push_back(10 - i); + } + + list1.sort(); + list2.sort(); + + std::list<int>::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<int> list1; + std::list<int> list2; + + for(int i = 0; i < 10; ++i) + { + list1.push_back(i); + list2.push_back(10 - i); + } + + list1.sort(); + list2.sort(); + + std::list<int>::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<int>()); + + list2.splice(list2.begin(), list1, node_of_interest); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/3_c++0x.cc b/libstdc++-v3/testsuite/23_containers/list/operations/3_c++0x.cc new file mode 100644 index 000000000..37a480606 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/3_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 "3.h" +#include <list> + +int main() +{ + operations03<std::list<int> >(); + 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 000000000..4e14f1ae6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/4.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2001, 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 "4.h" +#include <list> + +int main() +{ + operations04<std::list<int> >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/4.h b/libstdc++-v3/testsuite/23_containers/list/operations/4.h new file mode 100644 index 000000000..650282747 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/4.h @@ -0,0 +1,92 @@ +// Copyright (C) 2001, 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.4 list operations [lib.list.ops] + +#include <testsuite_hooks.h> + +// 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 +template<typename _Tp> +void +operations04() +{ + bool test __attribute__((unused)) = true; + typedef _Tp list_type; + + 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); + + list_type list0401(A, A + N); + list_type list0402(B, B + M); + list_type list0403(C, C + M); + list_type list0404(D, D + Q); + list_type 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 +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/42352.cc b/libstdc++-v3/testsuite/23_containers/list/operations/42352.cc new file mode 100644 index 000000000..7e6c9c4f1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/42352.cc @@ -0,0 +1,66 @@ +// { 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 <list> +#include <testsuite_hooks.h> + +// PR libstdc++/42352 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<int> l{3, 2, 4, 1, 5, 9, 0, 8, 6, 7}; + + l.sort(); + + for (auto it = l.begin(); it != l.end(); ++it) + { + static int nn = 0; + VERIFY( *it == nn++ ); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::list<int> l{3, 2, 4, 1, 5, 9, 0, 8, 6, 7}; + + struct compare + { + bool + operator()(int const& one, int const& two) const + { return one > two; } + }; + + l.sort(compare()); + + for (auto it = l.begin(); it != l.end(); ++it) + { + static int nn = 9; + VERIFY( *it == nn-- ); + } +} + +int main() +{ + test01(); + test02(); + 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 000000000..bcfbb81b7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/5.cc @@ -0,0 +1,31 @@ +// 2006-01-19 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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 "5.h" +#include <list> + +int main() +{ + typedef int value_type; + typedef __gnu_test::uneq_allocator<value_type> allocator_type; + typedef std::list<value_type, allocator_type> list_type; + + operations05<list_type>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/5.h b/libstdc++-v3/testsuite/23_containers/list/operations/5.h new file mode 100644 index 000000000..0820e8a69 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/5.h @@ -0,0 +1,134 @@ +// 2006-01-19 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.4 list operations [lib.list.ops] + +#include <stdexcept> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// Check the splice (and merge) bits of N1599. +template<typename _Tp> +void +operations05() +{ + bool test __attribute__((unused)) = true; + + typedef _Tp list_type; + typedef typename list_type::allocator_type allocator_type; + + 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); + + allocator_type alloc01(1), alloc02(2); + + list_type l01(data1, data1 + N1, alloc01); + const list_type l01_ref = l01; + + list_type l02(data2, data2 + N2, alloc02); + const list_type 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<int>()); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/pthread1.cc b/libstdc++-v3/testsuite/23_containers/list/pthread1.cc new file mode 100644 index 000000000..00dc817b1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/pthread1.cc @@ -0,0 +1,131 @@ +// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org> +// +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 +// 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/>. + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } + +// This multi-threading C++/STL/POSIX code adheres to rules outlined here: +// http://www.sgi.com/tech/stl/thread_safety.html +// +// It is believed to exercise the allocation code in a manner that +// should reveal memory leaks (and, under rare cases, race conditions, +// if the STL threading support is fubar'd). + +#include <list> +#include <cstdlib> +#include <pthread.h> + +const int thread_cycles = 10; +const int thread_pairs = 10; +const unsigned max_size = 100; +const int iters = 10000; + +class task_queue +{ + typedef std::list<int> list_type; + +public: + task_queue () + { + pthread_mutex_init (&fooLock, 0); + pthread_cond_init (&fooCond1, 0); + pthread_cond_init (&fooCond2, 0); + } + ~task_queue () + { + pthread_mutex_destroy (&fooLock); + pthread_cond_destroy (&fooCond1); + pthread_cond_destroy (&fooCond2); + } + + list_type foo; + pthread_mutex_t fooLock; + pthread_cond_t fooCond1; + pthread_cond_t fooCond2; +}; + +void* +produce(void* t) +{ + task_queue& tq = *(static_cast<task_queue*> (t)); + int num = 0; + while (num < iters) + { + pthread_mutex_lock (&tq.fooLock); + while (tq.foo.size () >= max_size) + pthread_cond_wait (&tq.fooCond1, &tq.fooLock); + tq.foo.push_back (num++); + pthread_cond_signal (&tq.fooCond2); + pthread_mutex_unlock (&tq.fooLock); + } + return 0; +} + +void* +consume(void* t) +{ + task_queue& tq = *(static_cast<task_queue*> (t)); + int num = 0; + while (num < iters) + { + pthread_mutex_lock (&tq.fooLock); + while (tq.foo.size () == 0) + pthread_cond_wait (&tq.fooCond2, &tq.fooLock); + if (tq.foo.front () != num++) + abort (); + tq.foo.pop_front (); + pthread_cond_signal (&tq.fooCond1); + pthread_mutex_unlock (&tq.fooLock); + } + return 0; +} + +int +main() +{ + pthread_t prod[thread_pairs]; + pthread_t cons[thread_pairs]; + + task_queue* tq[thread_pairs]; + +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (thread_pairs * 2); +#endif + + for (int j = 0; j < thread_cycles; j++) + { + for (int i = 0; i < thread_pairs; i++) + { + tq[i] = new task_queue; + pthread_create (&prod[i], 0, produce, static_cast<void*> (tq[i])); + pthread_create (&cons[i], 0, consume, static_cast<void*> (tq[i])); + } + + for (int i = 0; i < thread_pairs; i++) + { + pthread_join (prod[i], 0); + pthread_join (cons[i], 0); + delete tq[i]; + } + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/pthread5.cc b/libstdc++-v3/testsuite/23_containers/list/pthread5.cc new file mode 100644 index 000000000..4f4643721 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/pthread5.cc @@ -0,0 +1,125 @@ +// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org> +// Adpated from libstdc++/5464 submitted by jjessel@amadeus.net +// Jean-Francois JESSEL (Amadeus SAS Development) +// +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 +// 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/>. + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } + +#include <vector> +#include <list> +#include <string> +#include <cstdlib> +#include <pthread.h> + +#ifdef _GLIBCXX_HAVE_UNISTD_H +#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING +#endif + +#define NTHREADS 8 +#define LOOPS 20 + +struct tt_t +{ + char buf[100]; + int i; +}; + +void* +thread_function (void* arg) +{ + typedef std::vector<tt_t> vector_type; + typedef std::list<std::string*> list_type; + + int myid __attribute__((unused)) = *(int*) arg; + for (int i = 0; i < LOOPS; i++) + { + vector_type myvect1; + + for (int j = 0; j < 2000; j++) + { + vector_type myvect2; + tt_t v; + v.i = j; + myvect1.push_back (v); + myvect2.push_back (v); + list_type mylist; + std::string string_array[4]; + string_array[0] = "toto"; + string_array[1] = "titi"; + string_array[2] = "tata"; + string_array[3] = "tutu"; + for (int k = 0; k < 4; k++) + { + if (mylist.size ()) + { + list_type::iterator aIt; + for (aIt = mylist.begin (); aIt != mylist.end (); ++aIt) + { + if ((*aIt) == &(string_array[k])) + abort (); + } + } + mylist.push_back (&(string_array[k])); + } + } + } + + return arg; +} + +int +main () +{ + int worker; + pthread_t threads[NTHREADS]; + int ids[NTHREADS]; + void* status; + +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (NTHREADS); +#endif + + pthread_attr_t tattr; + int ret __attribute__((unused)) = pthread_attr_init (&tattr); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING + ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM); +#endif + + for (worker = 0; worker < NTHREADS; worker++) + { + ids[worker] = worker; + if (pthread_create(&threads[worker], &tattr, + thread_function, &ids[worker])) + abort (); + } + + for (worker = 0; worker < NTHREADS; worker++) + { + if (pthread_join(threads[worker], static_cast<void **>(&status))) + abort (); + + if (*((int *)status) != worker) + abort (); + } + + return (0); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/range_access.cc b/libstdc++-v3/testsuite/23_containers/list/range_access.cc new file mode 100644 index 000000000..768bd638a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <list> + +void +test01() +{ + std::list<int> l{1, 2, 3}; + std::begin(l); + std::end(l); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/citerators.cc new file mode 100644 index 000000000..ac5bdec98 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <testsuite_containers.h> + +int main() +{ + typedef std::list<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc new file mode 100644 index 000000000..96a14e4da --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc @@ -0,0 +1,36 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1491 } +// { dg-excess-errors "" } + +#include <list> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + typedef std::list<A> list_type; + list_type l; + l.assign(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor.cc new file mode 100644 index 000000000..5c0bf6f72 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor.cc @@ -0,0 +1,28 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + +// { dg-do compile } + +#include <list> + +void f() +{ + typedef std::list<int> list_type; + list_type l(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc new file mode 100644 index 000000000..cc10877fa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc @@ -0,0 +1,30 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1447 } +// { dg-excess-errors "" } + +#include <list> + +void f() +{ + typedef std::list<std::list<int> > list_type; + list_type l(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc new file mode 100644 index 000000000..acc64e4af --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc @@ -0,0 +1,31 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1447 } +// { dg-excess-errors "" } + +#include <list> +#include <utility> + +void f() +{ + typedef std::list<std::list<std::pair<char, char> > > list_type; + list_type l('a', 'b'); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc new file mode 100644 index 000000000..8df0ac528 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc @@ -0,0 +1,36 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1447 } +// { dg-excess-errors "" } + +#include <list> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + typedef std::list<A> list_type; + list_type l; + l.insert(l.begin(), 10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/exception/basic.cc new file mode 100644 index 000000000..33232f965 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/exception/basic.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <list> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::list<value_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..f3d16028e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/exception/generation_prohibited.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <list> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::list<value_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..02d8d0b25 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/exception/propagation_consistent.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <list> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::list<value_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..787fe3801 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <list> + +// { dg-do compile } + +template class std::list<int>; diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..78e026a7f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <list> + +template class std::list<int>; diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..50ae78560 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/2.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <list> +#include <testsuite_api.h> + +// { dg-do compile } + +// N.B. In C++0x mode we cannot instantiate with T == NonDefaultConstructible +// because of 23.3.4.1.4 +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +template class std::list<__gnu_test::NonDefaultConstructible>; +#endif diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..ddc34e4be --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <list> + +// { dg-do compile } + +// libstdc++/21770 +template class std::list<int, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..7ad82a365 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/explicit_instantiation/4.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <list> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::list<__gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..69d25cf70 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + + +// This file tests user specialization of library containers + +#include <list> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Allocator> + class list<user_type, Allocator> { }; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/typedefs.cc new file mode 100644 index 000000000..444ebb540 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <list> + +// Check container for required typedefs. +__gnu_test::types<std::list<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/map/14340.cc b/libstdc++-v3/testsuite/23_containers/map/14340.cc new file mode 100644 index 000000000..1ee9fc1c9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/14340.cc @@ -0,0 +1,34 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <map> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::map<int, int> container; + __gnu_test::conversion<container>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/18604.cc b/libstdc++-v3/testsuite/23_containers/map/18604.cc new file mode 100644 index 000000000..ba1b06485 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/18604.cc @@ -0,0 +1,42 @@ +// 2005-05-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include <map> diff --git a/libstdc++-v3/testsuite/23_containers/map/23781_neg.cc b/libstdc++-v3/testsuite/23_containers/map/23781_neg.cc new file mode 100644 index 000000000..e282c7546 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/23781_neg.cc @@ -0,0 +1,28 @@ +// 2005-09-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2009, 2010 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/>. +// + +// { dg-do compile } + +// libstdc++/23781 +#include <map> +#include <cstddef> + +std::map<int, int>::iterator it = NULL; // { dg-error "conversion" } +std::map<int, int>::const_iterator cit = NULL; // { dg-error "conversion" } diff --git a/libstdc++-v3/testsuite/23_containers/map/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/map/capacity/29134.cc new file mode 100644 index 000000000..303160801 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/capacity/29134.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2006, 2007, 2008, 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.3.1 map capacity + +#include <map> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::map<int, int> m; + + VERIFY( (m.max_size() == std::allocator<std::_Rb_tree_node< + std::pair<const int, int> > >().max_size()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/map/cons/moveable.cc new file mode 100644 index 000000000..47dbd40a2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on map (via swap). If the implementation changed +// this test may begin to fail. + +#include <map> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::map<int, int> a,b; + a[2]=0; + b[1]=0; + b = std::move(a); + VERIFY(b.find(2) != b.end() && a.find(1) == a.end()); + + std::map<int, int> c(std::move(b)); + VERIFY( c.find(2) != c.end()); + VERIFY( b.find(2) == b.end()); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/construct1_neg.cc new file mode 100644 index 000000000..72adcf42e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/construct2_neg.cc new file mode 100644 index 000000000..a9cb0e300 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/construct3_neg.cc new file mode 100644 index 000000000..7f88827db --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/construct4_neg.cc new file mode 100644 index 000000000..ce2eccc38 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/insert1_neg.cc new file mode 100644 index 000000000..7b868a7af --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/insert2_neg.cc new file mode 100644 index 000000000..93c6c7ef5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/insert3_neg.cc new file mode 100644 index 000000000..2802a0de5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/insert4_neg.cc new file mode 100644 index 000000000..a68d60108 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/map/debug/invalidation/1.cc new file mode 100644 index 000000000..a42112527 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/invalidation/1.cc @@ -0,0 +1,51 @@ +// Map iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/map> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::map; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + map<int, int> v1; + map<int, int> v2; + + v1[17] = 42; + + map<int, int>::iterator start = v1.begin(); + map<int, int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/map/debug/invalidation/2.cc new file mode 100644 index 000000000..85351da9f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/invalidation/2.cc @@ -0,0 +1,70 @@ +// Map iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/map> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::map; +using std::advance; + +bool test = true; + +// Erase +void test02() +{ + map<int, int> v; + for (int i = 0; i < 20; ++i) + v[i] = 20-i; + + // Single element erase (middle) + map<int, int>::iterator before = v.begin(); + map<int, int>::iterator at = before; + advance(at, 3); + map<int, int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + map<int, int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/dr130.cc b/libstdc++-v3/testsuite/23_containers/map/dr130.cc new file mode 100644 index 000000000..9186a621e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/dr130.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } +// 2008-07-22 Edward Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2009, 2010 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 <map> +#include <testsuite_hooks.h> + +// DR 130. Associative erase should return an iterator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + map<int, int> m0; + typedef map<int, int>::iterator iterator; + typedef map<int, int>::const_iterator const_iterator; + typedef map<int, int>::value_type value_type; + typedef pair<iterator, bool> insert_return_type; + + m0.insert(value_type(1, 1)); + insert_return_type irt1 = m0.insert(value_type(2, 2)); + insert_return_type irt2 = m0.insert(value_type(3, 3)); + + iterator pos1 = m0.erase(irt1.first); + VERIFY( pos1 == irt2.first ); + + iterator pos2 = m0.erase(irt2.first); + VERIFY( pos2 == m0.end() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + map<int, int> m0; + typedef map<int, int>::iterator iterator; + typedef map<int, int>::const_iterator const_iterator; + typedef map<int, int>::value_type value_type; + typedef pair<iterator, bool> insert_return_type; + + insert_return_type irt0 = m0.insert(value_type(1, 1)); + m0.insert(value_type(2, 2)); + insert_return_type irt2 = m0.insert(value_type(3, 3)); + insert_return_type irt3 = m0.insert(value_type(4, 4)); + + iterator pos1 = m0.erase(irt0.first, irt2.first); + VERIFY( pos1 == irt2.first ); + + iterator pos2 = m0.erase(irt2.first, ++irt3.first); + VERIFY( pos2 == m0.end() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/element_access/1.cc b/libstdc++-v3/testsuite/23_containers/map/element_access/1.cc new file mode 100644 index 000000000..ed30c1317 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/element_access/1.cc @@ -0,0 +1,78 @@ +// 2005-08-29 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 <map> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/23578 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::map<int, double> map_type; + + { + map_type m; + m[0] = 1.5; + + double& rd = m.at(0); + VERIFY( rd == 1.5 ); + try + { + m.at(1); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } + } + + { + map_type m; + m[1] = 2.5; + const map_type cm(m); + + const double& crd = cm.at(1); + VERIFY( crd == 2.5 ); + try + { + cm.at(0); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/element_access/2.cc b/libstdc++-v3/testsuite/23_containers/map/element_access/2.cc new file mode 100644 index 000000000..8f42066d0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/element_access/2.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + + Map m; + VERIFY( m.empty() ); + + m[rvalstruct(1)] = rvalstruct(17); + VERIFY( m.size() == 1 ); + VERIFY( (m.begin()->first).val == 1 ); + VERIFY( (m.begin()->second).val == 17 ); + VERIFY( m[rvalstruct(1)].val == 17 ); + + m[rvalstruct(2)] = rvalstruct(9); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(2)].val == 9 ); + + m[rvalstruct(1)] = rvalstruct(5); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(1)].val == 5 ); + VERIFY( m[rvalstruct(2)].val == 9 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/element_access/46148.cc b/libstdc++-v3/testsuite/23_containers/map/element_access/46148.cc new file mode 100644 index 000000000..d63f08b85 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/element_access/46148.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 <map> + +class moveable +{ +public: + moveable(moveable&&) { } + moveable() { } + + operator int() + { return 0; } +}; + +// libstdc++/46148 +int main() +{ + std::map<bool,moveable> the_map; + return the_map[true]; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/init-list.cc b/libstdc++-v3/testsuite/23_containers/map/init-list.cc new file mode 100644 index 000000000..b70753a3f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/init-list.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <map> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + map<int,double> m({ { 1, 1.0 }, { 2, 2.0 }, { 42, 237.0 } }); + VERIFY(m.size() == 3); + VERIFY(m[1] == 1.0); + VERIFY(m[2] == 2.0); + VERIFY(m[42] == 237.0); + + m = { {5, 55.0}, { 6, 66.0 } }; + VERIFY(m.size() == 2); + VERIFY(m[5] == 55.0); + VERIFY(m[6] == 66.0); + + m.insert({ { 7, 77.0 }, { 8, 88.0 } }); + VERIFY(m.size() == 4); + VERIFY(m[5] == 55.0); + VERIFY(m[6] == 66.0); + VERIFY(m[7] == 77.0); + VERIFY(m[8] == 88.0); + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/47628.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/47628.cc new file mode 100644 index 000000000..6c61b9430 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/47628.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } + +#include <map> + +struct Key +{ + Key() { } + + Key(const Key&) { } + + template<typename T> + Key(const T&) + { } + + bool operator<(const Key&) const; +}; + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +// libstdc++/47628 +void f() +{ + typedef std::map<Key, int> Map; + Map m; + m.insert(Map::value_type()); + Map::iterator i = m.begin(); + m.erase(i); +} +#endif diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/51142.cc new file mode 100644 index 000000000..f50b7b7e9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <map> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator<(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::map<X, int>& s, X x) +{ + std::map<X, int>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/1.cc new file mode 100644 index 000000000..037e00a68 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/1.cc @@ -0,0 +1,67 @@ +// 2001-08-23 pme & Sylvain.Pion@sophia.inria.fr + +// 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.3.1.2, table 69 -- map::insert(p,t) + +#include <map> +#include <testsuite_hooks.h> + +// { dg-do run } + +// libstdc++/3349 and +// http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01375.html +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::map<int, int> Map; + Map M; + Map::iterator hint; + + hint = M.insert(Map::value_type(7, 0)).first; + + M.insert(hint, Map::value_type(8, 1)); + M.insert(M.begin(), Map::value_type(9, 2)); + +#if 0 + // The tree's __rb_verify() member must be exposed in map<> before this + // will even compile. It's good test to see that "missing" entries are + // in fact present in the {map,tree}, but in the wrong place. + if (0) + { + Map::iterator i = M.begin(); + while (i != M.end()) { + std::cerr << '(' << i->first << ',' << i->second << ")\n"; + ++i; + } + std::cerr << "tree internal verify: " + << std::boolalpha << M.__rb_verify() << "\n"; + } +#endif + + VERIFY ( M.find(7) != M.end() ); + VERIFY ( M.find(8) != M.end() ); + VERIFY ( M.find(9) != M.end() ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/16813.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/16813.cc new file mode 100644 index 000000000..eab015380 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/16813.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2004, 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 <debug/map> +#include <testsuite_hooks.h> + +// libstdc++/16813 +void test01() +{ + using __gnu_debug::map; + bool test __attribute__((unused)) = true; + + map<int, float> m1, m2; + + m1[3] = 3.0f; + m1[11] = -67.0f; + + m2.insert(m1.begin(), m1.end()); + + VERIFY( m1 == m2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/2.cc new file mode 100644 index 000000000..5de89de54 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/2.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair(1, rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( p.first->first == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair(2, rvalstruct(3))); + std::pair<Map::iterator, bool> p2 = m.insert(Pair(2, rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( p1.first->first == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/3.cc new file mode 100644 index 000000000..e5827bfb3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/3.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( (p.first->first).val == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair(rvalstruct(2), + rvalstruct(3))); + std::pair<Map::iterator, bool> p2 = m.insert(Pair(rvalstruct(2), + rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (p1.first->first).val == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/4.cc new file mode 100644 index 000000000..28eba6472 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/4.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + Map::iterator p = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p == m.begin() ); + VERIFY( p->first == 1 ); + VERIFY( (p->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator p1 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + Map::iterator p2 = m.insert(p1, Pair(2, rvalstruct(7))); + VERIFY( m.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( p1->first == 2 ); + VERIFY( (p2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/5.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/5.cc new file mode 100644 index 000000000..3dc153b85 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/5.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + Map::iterator p = m.insert(m.begin(), Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p == m.begin() ); + VERIFY( (p->first).val == 1 ); + VERIFY( (p->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator p1 = m.insert(m.begin(), Pair(rvalstruct(2), + rvalstruct(3))); + Map::iterator p2 = m.insert(p1, Pair(rvalstruct(2), + rvalstruct(7))); + VERIFY( m.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( (p1->first).val == 2 ); + VERIFY( (p2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc new file mode 100644 index 000000000..b5fe2e374 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2005, 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 <map> +#include <testsuite_hooks.h> + +struct T { int i; }; + +// T must be LessThanComparable to pass concept-checks +bool operator<(T l, T r) { return l.i < r.i; } + +int swap_calls; + +namespace std +{ + template<> + void + map<T, int>::swap(map<T, int>&) + { ++swap_calls; } +} + +// Should use map specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::map<T, int> A; + std::map<T, int> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use map specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + map<T, int> A; + map<T, int> B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc new file mode 100644 index 000000000..741276b83 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc @@ -0,0 +1,146 @@ +// 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.3.1 map::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef map<char, int, less<char>, my_alloc> my_map; + + 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); + + map<char, int> map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + map<char, int> map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + map<char, int> map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + map<char, int> map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_map::size_type size01, size02; + + my_alloc alloc01(1); + + my_map map01(less<char>(), alloc01); + size01 = map01.size(); + my_map map02(less<char>(), alloc01); + size02 = map02.size(); + + map01.swap(map02); + VERIFY( map01.size() == size02 ); + VERIFY( map01.empty() ); + VERIFY( map02.size() == size01 ); + VERIFY( map02.empty() ); + + my_map map03(less<char>(), alloc01); + size01 = map03.size(); + my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map04.size(); + + map03.swap(map04); + VERIFY( map03.size() == size02 ); + VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) ); + VERIFY( map04.size() == size01 ); + VERIFY( map04.empty() ); + + my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map05.size(); + my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map06.size(); + + map05.swap(map06); + VERIFY( map05.size() == size02 ); + VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) ); + VERIFY( map06.size() == size01 ); + VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) ); + + my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map07.size(); + my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map08.size(); + + map07.swap(map08); + VERIFY( map07.size() == size02 ); + VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) ); + VERIFY( map08.size() == size01 ); + VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) ); + + my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map09.size(); + my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01); + size02 = map10.size(); + + map09.swap(map10); + VERIFY( map09.size() == size02 ); + VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) ); + VERIFY( map10.size() == size01 ); + VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) ); + + my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01); + size01 = map11.size(); + my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size02 = map12.size(); + + map11.swap(map12); + VERIFY( map11.size() == size02 ); + VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) ); + VERIFY( map12.size() == size01 ); + VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) ); + + my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map13.size(); + my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map14.size(); + + map13.swap(map14); + VERIFY( map13.size() == size02 ); + VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) ); + VERIFY( map14.size() == size01 ); + VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc new file mode 100644 index 000000000..68980e463 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc @@ -0,0 +1,175 @@ +// 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.3.1 map::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef map<char, int, less<char>, my_alloc> my_map; + + 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); + + map<char, int> map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + map<char, int> map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + map<char, int> map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + map<char, int> map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_map::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_map map01(less<char>(), alloc01); + size01 = map01.size(); + personality01 = map01.get_allocator().get_personality(); + my_map map02(less<char>(), alloc02); + size02 = map02.size(); + personality02 = map02.get_allocator().get_personality(); + + map01.swap(map02); + VERIFY( map01.size() == size02 ); + VERIFY( map01.empty() ); + VERIFY( map02.size() == size01 ); + VERIFY( map02.empty() ); + VERIFY( map01.get_allocator().get_personality() == personality02 ); + VERIFY( map02.get_allocator().get_personality() == personality01 ); + + my_map map03(less<char>(), alloc02); + size01 = map03.size(); + personality01 = map03.get_allocator().get_personality(); + my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map04.size(); + personality02 = map04.get_allocator().get_personality(); + + map03.swap(map04); + VERIFY( map03.size() == size02 ); + VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) ); + VERIFY( map04.size() == size01 ); + VERIFY( map04.empty() ); + VERIFY( map03.get_allocator().get_personality() == personality02 ); + VERIFY( map04.get_allocator().get_personality() == personality01 ); + + my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map05.size(); + personality01 = map05.get_allocator().get_personality(); + my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc02); + size02 = map06.size(); + personality02 = map06.get_allocator().get_personality(); + + map05.swap(map06); + VERIFY( map05.size() == size02 ); + VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) ); + VERIFY( map06.size() == size01 ); + VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) ); + VERIFY( map05.get_allocator().get_personality() == personality02 ); + VERIFY( map06.get_allocator().get_personality() == personality01 ); + + my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc02); + size01 = map07.size(); + personality01 = map07.get_allocator().get_personality(); + my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map08.size(); + personality02 = map08.get_allocator().get_personality(); + + map07.swap(map08); + VERIFY( map07.size() == size02 ); + VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) ); + VERIFY( map08.size() == size01 ); + VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) ); + VERIFY( map07.get_allocator().get_personality() == personality02 ); + VERIFY( map08.get_allocator().get_personality() == personality01 ); + + my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map09.size(); + personality01 = map09.get_allocator().get_personality(); + my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02); + size02 = map10.size(); + personality02 = map10.get_allocator().get_personality(); + + map09.swap(map10); + VERIFY( map09.size() == size02 ); + VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) ); + VERIFY( map10.size() == size01 ); + VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) ); + VERIFY( map09.get_allocator().get_personality() == personality02 ); + VERIFY( map10.get_allocator().get_personality() == personality01 ); + + my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02); + size01 = map11.size(); + personality01 = map11.get_allocator().get_personality(); + my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size02 = map12.size(); + personality02 = map12.get_allocator().get_personality(); + + map11.swap(map12); + VERIFY( map11.size() == size02 ); + VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) ); + VERIFY( map12.size() == size01 ); + VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) ); + VERIFY( map11.get_allocator().get_personality() == personality02 ); + VERIFY( map12.get_allocator().get_personality() == personality01 ); + + my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map13.size(); + personality01 = map13.get_allocator().get_personality(); + my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc02); + size02 = map14.size(); + personality02 = map14.get_allocator().get_personality(); + + map13.swap(map14); + VERIFY( map13.size() == size02 ); + VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) ); + VERIFY( map14.size() == size01 ); + VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) ); + VERIFY( map13.get_allocator().get_personality() == personality02 ); + VERIFY( map14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/operations/1.cc b/libstdc++-v3/testsuite/23_containers/map/operations/1.cc new file mode 100644 index 000000000..5ff32f6b0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/operations/1.cc @@ -0,0 +1,127 @@ +// 2006-11-25 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 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 <map> +#include <testsuite_hooks.h> + +// A few tests for equal_range, in the occasion of libstdc++/29385. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + map<int, int> m0; + typedef map<int, int>::iterator iterator; + typedef pair<iterator, bool> insert_return_type; + pair<iterator, iterator> pp0; + typedef map<int, int>::value_type value_type; + + pp0 = m0.equal_range(1); + VERIFY( m0.count(1) == 0 ); + VERIFY( pp0.first == m0.end() ); + VERIFY( pp0.second == m0.end() ); + + insert_return_type irt0 = m0.insert(value_type(1, 1)); + insert_return_type irt1 = m0.insert(value_type(2, 2)); + insert_return_type irt2 = m0.insert(value_type(3, 3)); + + pp0 = m0.equal_range(2); + VERIFY( m0.count(2) == 1 ); + VERIFY( *pp0.first == value_type(2, 2) ); + VERIFY( *pp0.second == value_type(3, 3) ); + VERIFY( pp0.first == irt1.first ); + VERIFY( --pp0.first == irt0.first ); + VERIFY( pp0.second == irt2.first ); + + m0.insert(value_type(3, 4)); + insert_return_type irt3 = m0.insert(value_type(3, 5)); + insert_return_type irt4 = m0.insert(value_type(4, 6)); + + pp0 = m0.equal_range(3); + VERIFY( m0.count(3) == 1 ); + VERIFY( *pp0.first == value_type(3, 3) ); + VERIFY( *pp0.second == value_type(4, 6) ); + VERIFY( pp0.first == irt2.first ); + VERIFY( --pp0.first == irt1.first ); + VERIFY( pp0.second == irt4.first ); + + insert_return_type irt5 = m0.insert(value_type(0, 7)); + m0.insert(value_type(1, 8)); + m0.insert(value_type(1, 9)); + m0.insert(value_type(1, 10)); + + pp0 = m0.equal_range(1); + VERIFY( m0.count(1) == 1 ); + VERIFY( *pp0.first == value_type(1, 1) ); + VERIFY( *pp0.second == value_type(2, 2) ); + VERIFY( pp0.first == irt0.first ); + VERIFY( --pp0.first == irt5.first ); + VERIFY( pp0.second == irt1.first ); + + insert_return_type irt6 = m0.insert(value_type(5, 11)); + m0.insert(value_type(5, 12)); + m0.insert(value_type(5, 13)); + + pp0 = m0.equal_range(5); + VERIFY( m0.count(5) == 1 ); + VERIFY( *pp0.first == value_type(5, 11) ); + VERIFY( pp0.first == irt6.first ); + VERIFY( --pp0.first == irt4.first ); + VERIFY( pp0.second == m0.end() ); + + m0.insert(value_type(4, 14)); + m0.insert(value_type(4, 15)); + m0.insert(value_type(4, 16)); + + pp0 = m0.equal_range(4); + VERIFY( m0.count(4) == 1 ); + VERIFY( *pp0.first == value_type(4, 6) ); + VERIFY( *pp0.second == value_type(5, 11) ); + VERIFY( pp0.first == irt4.first ); + VERIFY( --pp0.first == irt3.first ); + VERIFY( pp0.second == irt6.first ); + + m0.insert(value_type(0, 17)); + insert_return_type irt7 = m0.insert(value_type(0, 18)); + m0.insert(value_type(1, 19)); + + pp0 = m0.equal_range(0); + VERIFY( m0.count(0) == 1 ); + VERIFY( *pp0.first == value_type(0, 7) ); + VERIFY( *pp0.second == value_type(1, 1) ); + VERIFY( pp0.first == irt5.first ); + VERIFY( pp0.first == m0.begin() ); + VERIFY( pp0.second == irt0.first ); + + pp0 = m0.equal_range(1); + VERIFY( m0.count(1) == 1 ); + VERIFY( *pp0.first == value_type(1, 1) ); + VERIFY( *pp0.second == value_type(2, 2) ); + VERIFY( pp0.first == irt0.first ); + VERIFY( --pp0.first == irt7.first); + VERIFY( pp0.second == irt1.first ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc b/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc new file mode 100644 index 000000000..a28a8d62f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc @@ -0,0 +1,52 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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 <map> + +// libstdc++/31440 +struct DagNode +{ }; + +class MemoTable +{ +public: + void memoRewrite(); + +private: + struct dagNodeLt; + class MemoMap; + + MemoMap* memoMap; +}; + +struct MemoTable::dagNodeLt +{ + bool operator()(const DagNode*, const DagNode*); +}; + +class MemoTable::MemoMap +: public std::map<DagNode*, DagNode*, MemoTable::dagNodeLt> +{ }; + +void +MemoTable::memoRewrite() +{ + memoMap->find(0); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/operators/1.cc b/libstdc++-v3/testsuite/23_containers/map/operators/1.cc new file mode 100644 index 000000000..d58f17b6f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/operators/1.cc @@ -0,0 +1,49 @@ +// 2000-09-07 bgarcia@laurelnetworks.com + +// Copyright (C) 2000, 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.3.4 template class multiset + +#include <map> +#include <string> +#include <iostream> + +// libstdc++/737 +// http://gcc.gnu.org/ml/libstdc++/2000-11/msg00093.html +void test02() +{ + typedef std::map<int, int> MapInt; + + MapInt m; + + for (unsigned i = 0; i < 10; ++i) + m.insert(MapInt::value_type(i,i)); + + for (MapInt::const_iterator i = m.begin(); i != m.end(); ++i) + std::cerr << i->second << ' '; + + for (MapInt::const_iterator i = m.begin(); m.end() != i; ++i) + std::cerr << i->second << ' '; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/operators/1_neg.cc b/libstdc++-v3/testsuite/23_containers/map/operators/1_neg.cc new file mode 100644 index 000000000..c5fd9cd0d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/operators/1_neg.cc @@ -0,0 +1,45 @@ +// { dg-do compile } + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, +// 2008, 2009, 2010 +// 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.3.4 template class multiset negative tests +// 2000-09-07 bgarcia@laurelnetworks.com + +#include <map> +#include <string> + +// libstdc++/86: map & set iterator comparisons are not type-safe +void test01() +{ + bool test __attribute__((unused)) = true; + std::map<unsigned int, int> mapByIndex; + std::map<std::string, unsigned> mapByName; + + mapByIndex.insert(std::pair<unsigned, int>(0, 1)); + mapByIndex.insert(std::pair<unsigned, int>(6, 5)); + + std::map<unsigned, int>::iterator itr(mapByIndex.begin()); + + // NB: notice, it's not mapByIndex!! + test &= itr != mapByName.end(); // { dg-error "no" } + test &= itr == mapByName.end(); // { dg-error "no" } +} + +// { dg-excess-errors "" } diff --git a/libstdc++-v3/testsuite/23_containers/map/pthread6.cc b/libstdc++-v3/testsuite/23_containers/map/pthread6.cc new file mode 100644 index 000000000..38c20ed64 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/pthread6.cc @@ -0,0 +1,87 @@ +// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org> +// Adpated from libstdc++/5444 submitted by markus.breuer@materna.de +// +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 +// 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/>. + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } + +#include <string> +#include <map> +#include <vector> +#include <pthread.h> + +const int max_thread_count = 8; +const int loops = 100000; + +const char* my_default = "Hallo Welt!"; + +const std::size_t upper_limit = 2500; +const std::size_t lower_limit = 1000; + +typedef char charT; + +typedef std::string String; + +typedef String MyType; + +void* +thread_main (void*) +{ + typedef std::map<unsigned int,MyType> Map; + typedef Map::value_type Value_Pair; + Map myMap; + + for (int loop = 0; loop < loops; loop++) + { + String& str = myMap[loop]; + str.append (my_default); + myMap.insert (Value_Pair (loop, str)); + + if (myMap.size () > upper_limit) + { + while (myMap.size () > lower_limit) + { + Map::iterator it = myMap.begin (); + myMap.erase (it); + } + } + } + + return 0; +} + +int +main (void) +{ + pthread_t tid[max_thread_count]; + +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (max_thread_count); +#endif + + for (int i = 0; i < max_thread_count; i++) + pthread_create (&tid[i], 0, thread_main, 0); + + for (int i = 0; i < max_thread_count; i++) + pthread_join (tid[i], 0); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/range_access.cc b/libstdc++-v3/testsuite/23_containers/map/range_access.cc new file mode 100644 index 000000000..1e4e3c187 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <map> + +void +test01() +{ + std::map<int, double> m{{1, 1.0}, {2, 2.0}, {3, 3.0}}; + std::begin(m); + std::end(m); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/citerators.cc new file mode 100644 index 000000000..17db1e7da --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <map> +#include <testsuite_containers.h> + +int main() +{ + typedef std::map<int, int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/exception/basic.cc new file mode 100644 index 000000000..cb5e2daed --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/exception/basic.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <map> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit key_type; + typedef std::pair<const key_type, key_type> value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<key_type> compare_type; + typedef std::map<key_type, key_type, compare_type, allocator_type> test_type; + + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..7d67cd7fc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/exception/generation_prohibited.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random key_type; + typedef std::pair<const key_type, key_type> value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::less<key_type> compare_type; + typedef std::map<key_type, key_type, compare_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..eee010bd0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/exception/propagation_consistent.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit key_type; + typedef std::pair<const key_type, key_type> value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<key_type> compare_type; + typedef std::map<key_type, key_type, compare_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..792a8b4bc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <map> + +// { dg-do compile } + +template class std::map<int, double>; diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..3b35d54b0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <map> + +template class std::map<int, double>; diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..0a620e6ff --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/2.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// N.B. We cannot instantiate with T == NonDefaultConstructible +// because of 23.3.1.2. +template class std::map<__gnu_test::NonDefaultConstructible, double>; diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..d0ece3db1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <map> + +// { dg-do compile } + +// libstdc++/21770 +template class std::map<int, double, std::less<int>, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..2a3700add --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/explicit_instantiation/4.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::map<__gnu_test::OverloadedAddress, + __gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..8ede16a59 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 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/>. + + +// This file tests user specialization of library containers + +#include <map> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Data, typename Allocator> + class map<user_type, Data, Allocator> {}; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/map/requirements/typedefs.cc new file mode 100644 index 000000000..1325cc607 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <map> + +// Check container for required typedefs. +__gnu_test::types<std::map<int, long> > t; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/14340.cc b/libstdc++-v3/testsuite/23_containers/multimap/14340.cc new file mode 100644 index 000000000..431a47314 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/14340.cc @@ -0,0 +1,34 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <map> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::multimap<int, int> container; + __gnu_test::conversion<container>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/23781_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/23781_neg.cc new file mode 100644 index 000000000..50ec92906 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/23781_neg.cc @@ -0,0 +1,28 @@ +// 2005-09-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2009, 2010 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/>. +// + +// { dg-do compile } + +// libstdc++/23781 +#include <map> +#include <cstddef> + +std::multimap<int, int>::iterator it = NULL; // { dg-error "conversion" } +std::multimap<int, int>::const_iterator cit = NULL; // { dg-error "conversion" } diff --git a/libstdc++-v3/testsuite/23_containers/multimap/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/multimap/capacity/29134.cc new file mode 100644 index 000000000..a8e407daf --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/capacity/29134.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2006, 2007, 2008, 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.3.2 multimap capacity + +#include <map> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::multimap<int, int> mm; + + VERIFY( (mm.max_size() == std::allocator<std::_Rb_tree_node< + std::pair<const int, int> > >().max_size()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/multimap/cons/moveable.cc new file mode 100644 index 000000000..2f9744c11 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on multimap (via swap). If the implementation changed +// this test may begin to fail. + +#include <map> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::multimap<int, int> a,b; + a.insert(std::make_pair(2,0)); + b.insert(std::make_pair(1,0)); + b = std::move(a); + VERIFY(b.find(2) != b.end() && a.find(1) == a.end()); + + std::multimap<int, int> c(std::move(b)); + VERIFY( c.find(2) != c.end()); + VERIFY( b.find(2) == b.end()); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct1_neg.cc new file mode 100644 index 000000000..13f5763fb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct2_neg.cc new file mode 100644 index 000000000..9c389e199 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct3_neg.cc new file mode 100644 index 000000000..b5a5288f5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct4_neg.cc new file mode 100644 index 000000000..7c267f418 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert1_neg.cc new file mode 100644 index 000000000..879af771c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert2_neg.cc new file mode 100644 index 000000000..883ff148a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert3_neg.cc new file mode 100644 index 000000000..f75efb58b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert4_neg.cc new file mode 100644 index 000000000..0e5102b74 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/invalidation/1.cc new file mode 100644 index 000000000..2ea2aabc9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/invalidation/1.cc @@ -0,0 +1,52 @@ +// Multimap iterator invalidation tests + +// Copyright (C) 2003, 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 <debug/map> +#include <iterator> +#include <testsuite_hooks.h> +#include <utility> + +using __gnu_debug::multimap; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + multimap<int, int> v1; + multimap<int, int> v2; + + v1.insert(std::make_pair(17, 42)); + + multimap<int, int>::iterator start = v1.begin(); + multimap<int, int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/invalidation/2.cc new file mode 100644 index 000000000..756c951a0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/invalidation/2.cc @@ -0,0 +1,71 @@ +// Multimap iterator invalidation tests + +// Copyright (C) 2003, 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 <debug/map> +#include <iterator> +#include <testsuite_hooks.h> +#include <utility> + +using __gnu_debug::multimap; +using std::advance; + +bool test = true; + +// Erase +void test02() +{ + multimap<int, int> v; + for (int i = 0; i < 20; ++i) + v.insert(std::make_pair(i, 20-i)); + + // Single element erase (middle) + multimap<int, int>::iterator before = v.begin(); + multimap<int, int>::iterator at = before; + advance(at, 3); + multimap<int, int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + multimap<int, int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/dr130.cc b/libstdc++-v3/testsuite/23_containers/multimap/dr130.cc new file mode 100644 index 000000000..086848706 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/dr130.cc @@ -0,0 +1,87 @@ +// { 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on multiset (via swap). If the implementation changed +// this test may begin to fail. + +#include <map> +#include <vector> +#include <testsuite_hooks.h> + +using namespace std; + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multimap<int, int> mm0; + typedef multimap<int, int>::iterator iterator; + typedef multimap<int, int>::const_iterator const_iterator; + typedef multimap<int, int>::value_type value_type; + typedef iterator insert_return_type; + + vector<insert_return_type> irt; + for (int i = 1; i <= 4; ++i) + for (int j = 1; j <= i; ++j) + irt.push_back( mm0.insert( value_type( i, i ) ) ); + + iterator pos1 = mm0.erase(irt[1]); + VERIFY( pos1 == irt[2] ); + + iterator pos2 = mm0.erase(irt[2]); + VERIFY( pos2 == irt[3] ); + + iterator pos3 = mm0.erase(irt[9]); + VERIFY( pos3 == mm0.end() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multimap<int, int> mm0; + typedef multimap<int, int>::iterator iterator; + typedef multimap<int, int>::const_iterator const_iterator; + typedef multimap<int, int>::value_type value_type; + typedef iterator insert_return_type; + + vector<insert_return_type> irt; + for (int i = 1; i <= 4; ++i) + for (int j = 1; j <= i; ++j) + irt.push_back( mm0.insert( value_type( i, i ) ) ); + + iterator pos1 = mm0.erase(irt[3], irt[6]); + VERIFY( pos1 == irt[6] ); + + iterator pos2 = mm0.erase(irt[6], ++irt[9]); + VERIFY( pos2 == mm0.end() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/init-list.cc b/libstdc++-v3/testsuite/23_containers/multimap/init-list.cc new file mode 100644 index 000000000..ea231cd37 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/init-list.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <map> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + typedef multimap<int,double> Container; + typedef Container::iterator iterator; + typedef pair<iterator,iterator> itpair; + Container m({ { 1, 1.0 }, { 1, 2.0 }, { 1, 237.0 } }); + VERIFY(m.size() == 3); + itpair ip = m.equal_range(1); + VERIFY(distance(ip.first, ip.second) == 3); + iterator i = ip.first; + VERIFY((*i++).second == 1.0); + VERIFY((*i++).second == 2.0); + VERIFY((*i++).second == 237.0); + + m = { {5, 55.0}, { 5, 66.0 }, { 42, 4242.0 } }; + VERIFY(m.size() == 3); + ip = m.equal_range(5); + VERIFY(distance(ip.first, ip.second) == 2); + i = ip.first; + VERIFY((*i++).second == 55.0); + VERIFY((*i++).second == 66.0); + + m.insert({ { 7, 77.0 }, { 7, 88.0 } }); + VERIFY(m.size() == 5); + VERIFY(m.count(5) == 2); + VERIFY(m.count(42) == 1); + VERIFY(m.count(7) == 2); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/47628.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/47628.cc new file mode 100644 index 000000000..c45013a12 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/47628.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } + +#include <map> + +struct Key +{ + Key() { } + + Key(const Key&) { } + + template<typename T> + Key(const T&) + { } + + bool operator<(const Key&) const; +}; + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +// libstdc++/47628 +void f() +{ + typedef std::multimap<Key, int> MMap; + MMap mm; + mm.insert(MMap::value_type()); + MMap::iterator i = mm.begin(); + mm.erase(i); +} +#endif diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/51142.cc new file mode 100644 index 000000000..ee687f77c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <map> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator<(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::multimap<X, int>& s, X x) +{ + std::multimap<X, int>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc new file mode 100644 index 000000000..f07e97d7d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(2, rvalstruct(3))); + m.insert(Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc new file mode 100644 index 000000000..56453cade --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc new file mode 100644 index 000000000..e89251962 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/22102.cc @@ -0,0 +1,140 @@ +// 2006-01-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.3.2 Class template multimap + +#include <map> +#include <testsuite_hooks.h> + +// libstdc++/22102 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::multimap<int, int> Mmap; + typedef Mmap::value_type value_type; + typedef Mmap::iterator iterator; + + Mmap mm1; + + const iterator it1 = mm1.insert(value_type(0, 0)); + const iterator it2 = mm1.insert(value_type(1, 1)); + const iterator it3 = mm1.insert(value_type(2, 2)); + + const value_type vt1(2, 1); + const iterator it4 = mm1.insert(it1, vt1); + iterator it5 = it4; + iterator it6 = it4; + VERIFY( mm1.size() == 4 ); + VERIFY( *it4 == vt1 ); + VERIFY( ++it5 == it3 ); + VERIFY( --it6 == it2 ); + VERIFY( *it5 == *it3 ); + VERIFY( *it6 == *it2 ); + + const value_type vt2(2, 0); + const iterator it7 = mm1.insert(mm1.begin(), vt2); + iterator it8 = it7; + iterator it9 = it7; + VERIFY( mm1.size() == 5 ); + VERIFY( *it7 == vt2 ); + VERIFY( ++it8 == it4 ); + VERIFY( --it9 == it2 ); + VERIFY( *it8 == *it4 ); + VERIFY( *it9 == *it2 ); + + const value_type vt3(2, -1); + const iterator it10 = mm1.insert(it1, vt3); + iterator it11 = it10; + iterator it12 = it10; + VERIFY( mm1.size() == 6 ); + VERIFY( *it10 == vt3 ); + VERIFY( ++it11 == it7 ); + VERIFY( --it12 == it2 ); + VERIFY( *it11 == *it7 ); + VERIFY( *it12 == *it2 ); + + const value_type vt4(0, 1); + const iterator it13 = mm1.insert(it10, vt4); + iterator it14 = it13; + iterator it15 = it13; + VERIFY( mm1.size() == 7 ); + VERIFY( *it13 == vt4 ); + VERIFY( ++it14 == it2 ); + VERIFY( --it15 == it1 ); + VERIFY( *it14 == *it2 ); + VERIFY( *it15 == *it1 ); + + const value_type vt5(1, 0); + const iterator it16 = mm1.insert(it13, vt5); + iterator it17 = it16; + iterator it18 = it16; + VERIFY( mm1.size() == 8 ); + VERIFY( *it16 == vt5 ); + VERIFY( ++it17 == it2 ); + VERIFY( --it18 == it13 ); + VERIFY( *it17 == *it2 ); + VERIFY( *it18 == *it13 ); + + const value_type vt6(0, -1); + const iterator it19 = mm1.insert(it1, vt6); + iterator it20 = it19; + VERIFY( mm1.size() == 9 ); + VERIFY( *it19 == vt6 ); + VERIFY( it19 == mm1.begin() ); + VERIFY( ++it20 == it1 ); + VERIFY( *it20 == *it1 ); + + const value_type vt7(3, 3); + const iterator it21 = mm1.insert(it19, vt7); + iterator it22 = it21; + iterator it23 = it21; + VERIFY( mm1.size() == 10 ); + VERIFY( *it21 == vt7 ); + VERIFY( ++it22 == mm1.end() ); + VERIFY( --it23 == it3 ); + VERIFY( *it23 == *it3 ); + + const value_type vt8(2, 3); + const iterator it24 = mm1.insert(mm1.end(), vt8); + iterator it25 = it24; + iterator it26 = it24; + VERIFY( mm1.size() == 11 ); + VERIFY( *it24 == vt8 ); + VERIFY( ++it25 == it21 ); + VERIFY( --it26 == it3 ); + VERIFY( *it25 == *it21 ); + VERIFY( *it26 == *it3 ); + + const value_type vt9(3, 2); + const iterator it27 = mm1.insert(it3, vt9); + iterator it28 = it27; + iterator it29 = it27; + VERIFY( mm1.size() == 12 ); + VERIFY( *it27 == vt9 ); + VERIFY( ++it28 == it21 ); + VERIFY( --it29 == it24 ); + VERIFY( *it28 == *it21 ); + VERIFY( *it29 == *it24 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc new file mode 100644 index 000000000..dddd8c885 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + m.insert(i0, Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc new file mode 100644 index 000000000..a53852cc1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), + Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(i0, Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc new file mode 100644 index 000000000..2b9a7442c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2005, 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 <map> +#include <testsuite_hooks.h> + +struct T { int i; }; + +// T must be LessThanComparable to pass concept-checks +bool operator<(T l, T r) { return l.i < r.i; } + +int swap_calls; + +namespace std +{ + template<> + void + multimap<T, int>::swap(multimap<T, int>&) + { ++swap_calls; } +} + +// Should use multimap specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::multimap<T, int> A; + std::multimap<T, int> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use multimap specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + multimap<T, int> A; + multimap<T, int> B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc new file mode 100644 index 000000000..463409b6d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc @@ -0,0 +1,146 @@ +// 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.3.2 multimap::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + 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); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1); + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + my_mmap mmap02(less<char>(), alloc01); + size02 = mmap02.size(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + + my_mmap mmap03(less<char>(), alloc01); + size01 = mmap03.size(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap06.size(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap07.size(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size02 = mmap10.size(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size01 = mmap11.size(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap14.size(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc new file mode 100644 index 000000000..6f553df0e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc @@ -0,0 +1,175 @@ +// 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.3.2 multimap::swap + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + 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); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + personality01 = mmap01.get_allocator().get_personality(); + my_mmap mmap02(less<char>(), alloc02); + size02 = mmap02.size(); + personality02 = mmap02.get_allocator().get_personality(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + VERIFY( mmap01.get_allocator().get_personality() == personality02 ); + VERIFY( mmap02.get_allocator().get_personality() == personality01 ); + + my_mmap mmap03(less<char>(), alloc02); + size01 = mmap03.size(); + personality01 = mmap03.get_allocator().get_personality(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + personality02 = mmap04.get_allocator().get_personality(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + VERIFY( mmap03.get_allocator().get_personality() == personality02 ); + VERIFY( mmap04.get_allocator().get_personality() == personality01 ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + personality01 = mmap05.get_allocator().get_personality(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc02); + size02 = mmap06.size(); + personality02 = mmap06.get_allocator().get_personality(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + VERIFY( mmap05.get_allocator().get_personality() == personality02 ); + VERIFY( mmap06.get_allocator().get_personality() == personality01 ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc02); + size01 = mmap07.size(); + personality01 = mmap07.get_allocator().get_personality(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + personality02 = mmap08.get_allocator().get_personality(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + VERIFY( mmap07.get_allocator().get_personality() == personality02 ); + VERIFY( mmap08.get_allocator().get_personality() == personality01 ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + personality01 = mmap09.get_allocator().get_personality(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size02 = mmap10.size(); + personality02 = mmap10.get_allocator().get_personality(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + VERIFY( mmap09.get_allocator().get_personality() == personality02 ); + VERIFY( mmap10.get_allocator().get_personality() == personality01 ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size01 = mmap11.size(); + personality01 = mmap11.get_allocator().get_personality(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + personality02 = mmap12.get_allocator().get_personality(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + VERIFY( mmap11.get_allocator().get_personality() == personality02 ); + VERIFY( mmap12.get_allocator().get_personality() == personality01 ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + personality01 = mmap13.get_allocator().get_personality(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc02); + size02 = mmap14.size(); + personality02 = mmap14.get_allocator().get_personality(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); + VERIFY( mmap13.get_allocator().get_personality() == personality02 ); + VERIFY( mmap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/operations/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/operations/1.cc new file mode 100644 index 000000000..0c44e5454 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/operations/1.cc @@ -0,0 +1,126 @@ +// 2006-11-25 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 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 <map> +#include <testsuite_hooks.h> + +// A few tests for equal_range, in the occasion of libstdc++/29385. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multimap<int, int> mm0; + typedef multimap<int, int>::iterator iterator; + pair<iterator, iterator> pp0; + typedef multimap<int, int>::value_type value_type; + + pp0 = mm0.equal_range(1); + VERIFY( mm0.count(1) == 0 ); + VERIFY( pp0.first == mm0.end() ); + VERIFY( pp0.second == mm0.end() ); + + iterator iter0 = mm0.insert(value_type(1, 1)); + iterator iter1 = mm0.insert(value_type(2, 2)); + iterator iter2 = mm0.insert(value_type(3, 3)); + + pp0 = mm0.equal_range(2); + VERIFY( mm0.count(2) == 1 ); + VERIFY( *pp0.first == value_type(2, 2) ); + VERIFY( *pp0.second == value_type(3, 3) ); + VERIFY( pp0.first == iter1 ); + VERIFY( --pp0.first == iter0 ); + VERIFY( pp0.second == iter2 ); + + mm0.insert(value_type(3, 4)); + iterator iter3 = mm0.insert(value_type(3, 5)); + iterator iter4 = mm0.insert(value_type(4, 6)); + + pp0 = mm0.equal_range(3); + VERIFY( mm0.count(3) == 3 ); + VERIFY( *pp0.first == value_type(3, 3) ); + VERIFY( *pp0.second == value_type(4, 6) ); + VERIFY( pp0.first == iter2 ); + VERIFY( --pp0.first == iter1 ); + VERIFY( pp0.second == iter4 ); + + iterator iter5 = mm0.insert(value_type(0, 7)); + mm0.insert(value_type(1, 8)); + mm0.insert(value_type(1, 9)); + mm0.insert(value_type(1, 10)); + + pp0 = mm0.equal_range(1); + VERIFY( mm0.count(1) == 4 ); + VERIFY( *pp0.first == value_type(1, 1) ); + VERIFY( *pp0.second == value_type(2, 2) ); + VERIFY( pp0.first == iter0 ); + VERIFY( --pp0.first == iter5 ); + VERIFY( pp0.second == iter1 ); + + iterator iter6 = mm0.insert(value_type(5, 11)); + mm0.insert(value_type(5, 12)); + mm0.insert(value_type(5, 13)); + + pp0 = mm0.equal_range(5); + VERIFY( mm0.count(5) == 3 ); + VERIFY( *pp0.first == value_type(5, 11) ); + VERIFY( pp0.first == iter6 ); + VERIFY( --pp0.first == iter4 ); + VERIFY( pp0.second == mm0.end() ); + + mm0.insert(value_type(4, 14)); + mm0.insert(value_type(4, 15)); + mm0.insert(value_type(4, 16)); + + pp0 = mm0.equal_range(4); + VERIFY( mm0.count(4) == 4 ); + VERIFY( *pp0.first == value_type(4, 6) ); + VERIFY( *pp0.second == value_type(5, 11) ); + VERIFY( pp0.first == iter4 ); + VERIFY( --pp0.first == iter3 ); + VERIFY( pp0.second == iter6 ); + + mm0.insert(value_type(0, 17)); + iterator iter7 = mm0.insert(value_type(0, 18)); + mm0.insert(value_type(1, 19)); + + pp0 = mm0.equal_range(0); + VERIFY( mm0.count(0) == 3 ); + VERIFY( *pp0.first == value_type(0, 7) ); + VERIFY( *pp0.second == value_type(1, 1) ); + VERIFY( pp0.first == iter5 ); + VERIFY( pp0.first == mm0.begin() ); + VERIFY( pp0.second == iter0 ); + + pp0 = mm0.equal_range(1); + VERIFY( mm0.count(1) == 5 ); + VERIFY( *pp0.first == value_type(1, 1) ); + VERIFY( *pp0.second == value_type(2, 2) ); + VERIFY( pp0.first == iter0 ); + VERIFY( --pp0.first == iter7 ); + VERIFY( pp0.second == iter1 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc b/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc new file mode 100644 index 000000000..0f1c5bc53 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <map> + +void +test01() +{ + std::multimap<int, double> mm{{1, 1.0}, {2, 2.0}, {3, 3.0}}; + std::begin(mm); + std::end(mm); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/citerators.cc new file mode 100644 index 000000000..15773cb51 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <map> +#include <testsuite_containers.h> + +int main() +{ + typedef std::multimap<int, int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/basic.cc new file mode 100644 index 000000000..6f5b6aed9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/basic.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <map> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit key_type; + typedef std::pair<const key_type, key_type> value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<key_type> compare_type; + typedef std::multimap<key_type, key_type, compare_type, allocator_type> test_type; + + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..c34586b2e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/generation_prohibited.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random key_type; + typedef std::pair<const key_type, key_type> value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::less<key_type> compare_type; + typedef std::multimap<key_type, key_type, compare_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..8e1fef298 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/exception/propagation_consistent.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit key_type; + typedef std::pair<const key_type, key_type> value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<key_type> compare_type; + typedef std::multimap<key_type, key_type, compare_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..0b7fd08c6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <map> + +// { dg-do compile } + +template class std::multimap<int, double>; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..be8fcb049 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <map> + +template class std::multimap<int, double>; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..4d6165ffe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/2.cc @@ -0,0 +1,28 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +template class std::multimap<__gnu_test::NonDefaultConstructible, + __gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..ae673cd8e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <map> + +// { dg-do compile } + +// libstdc++/21770 +template class std::multimap<int, double, std::less<int>, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..82bd4cda8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/explicit_instantiation/4.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::multimap<__gnu_test::OverloadedAddress, + __gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..745ba0028 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 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/>. + + +// This file tests user specialization of library containers + +#include <map> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Data, typename Allocator> + class multimap<user_type, Data, Allocator> {}; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/multimap/requirements/typedefs.cc new file mode 100644 index 000000000..38a4bc535 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <map> + +// Check container for required typedefs. +__gnu_test::types<std::multimap<int, long> > t; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/14340.cc b/libstdc++-v3/testsuite/23_containers/multiset/14340.cc new file mode 100644 index 000000000..cbc29e914 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/14340.cc @@ -0,0 +1,34 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <set> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::multiset<int> container; + __gnu_test::conversion<container>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/23781_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/23781_neg.cc new file mode 100644 index 000000000..6b0bacf95 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/23781_neg.cc @@ -0,0 +1,28 @@ +// 2005-09-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2009, 2010 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/>. +// + +// { dg-do compile } + +// libstdc++/23781 +#include <set> +#include <cstddef> + +std::multiset<int>::iterator it = NULL; // { dg-error "conversion" } +std::multiset<int>::const_iterator cit = NULL; // { dg-error "conversion" } diff --git a/libstdc++-v3/testsuite/23_containers/multiset/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/multiset/capacity/29134.cc new file mode 100644 index 000000000..0a05f83c5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/capacity/29134.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2006, 2007, 2008, 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.3.4 multiset capacity + +#include <set> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::multiset<int> ms; + + VERIFY( ms.max_size() + == std::allocator<std::_Rb_tree_node<int> >().max_size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/multiset/cons/moveable.cc new file mode 100644 index 000000000..527e66e95 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on multiset (via swap). If the implementation changed +// this test may begin to fail. + +#include <set> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::multiset<int> a,b; + a.insert(2); + b.insert(1); + b = std::move(a); + VERIFY(b.find(2) != b.end() && a.find(1) == a.end()); + + std::multiset<int> c(std::move(b)); + VERIFY( c.find(2) != c.end()); + VERIFY( b.find(2) == b.end()); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct1_neg.cc new file mode 100644 index 000000000..04b0e33f9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct2_neg.cc new file mode 100644 index 000000000..d7dd965d3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct3_neg.cc new file mode 100644 index 000000000..cc3e1471d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct4_neg.cc new file mode 100644 index 000000000..181f4f902 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert1_neg.cc new file mode 100644 index 000000000..32f20a90b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert2_neg.cc new file mode 100644 index 000000000..699f0dd47 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert3_neg.cc new file mode 100644 index 000000000..92f864d60 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert4_neg.cc new file mode 100644 index 000000000..a0881075f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/invalidation/1.cc new file mode 100644 index 000000000..5b81b1eea --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/invalidation/1.cc @@ -0,0 +1,51 @@ +// Multiset iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::multiset; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + multiset<int> v1; + multiset<int> v2; + + v1.insert(17); + + multiset<int>::iterator start = v1.begin(); + multiset<int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/invalidation/2.cc new file mode 100644 index 000000000..be4eeb42d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/invalidation/2.cc @@ -0,0 +1,69 @@ +// Multiset iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::multiset; +using std::advance; + +// Erase +void test02() +{ + bool test __attribute__((unused)) = true; + multiset<int> v; + for (int i = 0; i < 20; ++i) + v.insert(i); + + // Single element erase (middle) + multiset<int>::iterator before = v.begin(); + multiset<int>::iterator at = before; + advance(at, 3); + multiset<int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + multiset<int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/dr130.cc b/libstdc++-v3/testsuite/23_containers/multiset/dr130.cc new file mode 100644 index 000000000..52392fcc1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/dr130.cc @@ -0,0 +1,85 @@ +// { 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on multiset (via swap). If the implementation changed +// this test may begin to fail. + +#include <set> +#include <vector> +#include <testsuite_hooks.h> + +using namespace std; + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multiset<int> ms0; + typedef multiset<int>::iterator iterator; + typedef multiset<int>::const_iterator const_iterator; + typedef iterator insert_return_type; + + vector<insert_return_type> irt; + for ( int i = 1; i <= 4; ++i ) + for (int j = 1; j <= i; ++j) + irt.push_back( ms0.insert( i ) ); + + iterator pos1 = ms0.erase(irt[1]); + VERIFY( pos1 == irt[2] ); + + iterator pos2 = ms0.erase(irt[2]); + VERIFY( pos2 == irt[3] ); + + iterator pos3 = ms0.erase(irt[9]); + VERIFY( pos3 == ms0.end() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multiset<int> ms0; + typedef multiset<int>::iterator iterator; + typedef multiset<int>::const_iterator const_iterator; + typedef iterator insert_return_type; + + vector<insert_return_type> irt; + for ( int i = 1; i <= 4; ++i ) + for (int j = 1; j <= i; ++j) + irt.push_back( ms0.insert( i ) ); + + iterator pos1 = ms0.erase(irt[3], irt[6]); + VERIFY( pos1 == irt[6] ); + + iterator pos2 = ms0.erase(irt[6], ++irt[9]); + VERIFY( pos2 == ms0.end() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/init-list.cc b/libstdc++-v3/testsuite/23_containers/multiset/init-list.cc new file mode 100644 index 000000000..a8721db99 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/init-list.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <set> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + multiset<int> m({ 1, 5, 5, 37 }); + VERIFY(m.size() == 4); + VERIFY(m.count(1) == 1); + VERIFY(m.count(5) == 2); + VERIFY(m.count(37) == 1); + VERIFY(m.count(42) == 0); + + m = { 28, 37, 37, 37, 102 }; + VERIFY(m.size() == 5); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 3); + VERIFY(m.count(102) == 1); + VERIFY(m.count(1) == 0); + + m.insert({ 42, 42 }); + VERIFY(m.size() == 7); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 3); + VERIFY(m.count(102) == 1); + VERIFY(m.count(42) == 2); + VERIFY(m.count(1) == 0); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/51142.cc new file mode 100644 index 000000000..c5beb6a8d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <set> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator<(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::multiset<X>& s, X x) +{ + std::multiset<X>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/1.cc new file mode 100644 index 000000000..87b1d3635 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/1.cc @@ -0,0 +1,64 @@ +// 1999-06-24 bkoz + +// Copyright (C) 1999, 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.3.4 template class multiset + +#include <sstream> +#include <iterator> +#include <set> +#include <algorithm> +#include <testsuite_hooks.h> + +namespace std +{ + std::ostream& + operator<<(std::ostream& os, std::pair<int, int> const& p) + { return os << p.first << ' ' << p.second; } +} + +bool +operator<(std::pair<int, int> const& lhs, std::pair<int, int> const& rhs) +{ return lhs.first < rhs.first; } + +int main () +{ + bool test __attribute__((unused)) = true; + typedef std::multiset<std::pair<int, int> >::iterator iterator; + std::pair<int, int> p(69, 0); + std::multiset<std::pair<int, int> > s; + + for (p.second = 0; p.second < 5; ++p.second) + s.insert(p); + for (iterator it = s.begin(); it != s.end(); ++it) + if (it->second < 5) + { + s.insert(it, p); + ++p.second; + } + + std::ostringstream stream; + std::copy(s.begin(), s.end(), + std::ostream_iterator<std::pair<int, int> >(stream, "\n")); + const std::string expected("69 0\n69 1\n69 2\n69 3\n69 4\n" + "69 5\n69 6\n69 7\n69 8\n69 9\n"); + std::string tested(stream.str()); + VERIFY( tested == expected ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/2.cc new file mode 100644 index 000000000..dcd3bd0b7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/2.cc @@ -0,0 +1,83 @@ +// 2005-01-17 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 <set> +#include <testsuite_hooks.h> + +// A few tests for insert with hint, in the occasion of libstdc++/19422 +// and libstdc++/19433. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multiset<int> ms0, ms1; + multiset<int>::iterator iter1; + + ms0.insert(1); + ms1.insert(ms1.end(), 1); + VERIFY( ms0 == ms1 ); + + ms0.insert(3); + ms1.insert(ms1.begin(), 3); + VERIFY( ms0 == ms1 ); + + ms0.insert(4); + iter1 = ms1.insert(ms1.end(), 4); + VERIFY( ms0 == ms1 ); + + ms0.insert(6); + ms1.insert(iter1, 6); + VERIFY( ms0 == ms1 ); + + ms0.insert(2); + ms1.insert(ms1.begin(), 2); + VERIFY( ms0 == ms1 ); + + ms0.insert(7); + ms1.insert(ms1.end(), 7); + VERIFY( ms0 == ms1 ); + + ms0.insert(5); + ms1.insert(ms1.find(4), 5); + VERIFY( ms0 == ms1 ); + + ms0.insert(0); + ms1.insert(ms1.end(), 0); + VERIFY( ms0 == ms1 ); + + ms0.insert(8); + ms1.insert(ms1.find(3), 8); + VERIFY( ms0 == ms1 ); + + ms0.insert(9); + ms1.insert(ms1.end(), 9); + VERIFY( ms0 == ms1 ); + + ms0.insert(10); + ms1.insert(ms1.begin(), 10); + VERIFY( ms0 == ms1 ); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/22102.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/22102.cc new file mode 100644 index 000000000..3e6d92602 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/22102.cc @@ -0,0 +1,140 @@ +// 2006-01-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.3.4 Class template multiset + +#include <set> +#include <testsuite_hooks.h> + +// libstdc++/22102 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::multiset<int> Mset; + typedef Mset::value_type value_type; + typedef Mset::iterator iterator; + + Mset ms1; + + const iterator it1 = ms1.insert(value_type(0)); + const iterator it2 = ms1.insert(value_type(1)); + const iterator it3 = ms1.insert(value_type(2)); + + const value_type vt1(2); + const iterator it4 = ms1.insert(it1, vt1); + iterator it5 = it4; + iterator it6 = it4; + VERIFY( ms1.size() == 4 ); + VERIFY( *it4 == vt1 ); + VERIFY( ++it5 == it3 ); + VERIFY( --it6 == it2 ); + VERIFY( *it5 == *it3 ); + VERIFY( *it6 == *it2 ); + + const value_type vt2(2); + const iterator it7 = ms1.insert(ms1.begin(), vt2); + iterator it8 = it7; + iterator it9 = it7; + VERIFY( ms1.size() == 5 ); + VERIFY( *it7 == vt2 ); + VERIFY( ++it8 == it4 ); + VERIFY( --it9 == it2 ); + VERIFY( *it8 == *it4 ); + VERIFY( *it9 == *it2 ); + + const value_type vt3(2); + const iterator it10 = ms1.insert(it1, vt3); + iterator it11 = it10; + iterator it12 = it10; + VERIFY( ms1.size() == 6 ); + VERIFY( *it10 == vt3 ); + VERIFY( ++it11 == it7 ); + VERIFY( --it12 == it2 ); + VERIFY( *it11 == *it7 ); + VERIFY( *it12 == *it2 ); + + const value_type vt4(0); + const iterator it13 = ms1.insert(it10, vt4); + iterator it14 = it13; + iterator it15 = it13; + VERIFY( ms1.size() == 7 ); + VERIFY( *it13 == vt4 ); + VERIFY( ++it14 == it2 ); + VERIFY( --it15 == it1 ); + VERIFY( *it14 == *it2 ); + VERIFY( *it15 == *it1 ); + + const value_type vt5(1); + const iterator it16 = ms1.insert(it13, vt5); + iterator it17 = it16; + iterator it18 = it16; + VERIFY( ms1.size() == 8 ); + VERIFY( *it16 == vt5 ); + VERIFY( ++it17 == it2 ); + VERIFY( --it18 == it13 ); + VERIFY( *it17 == *it2 ); + VERIFY( *it18 == *it13 ); + + const value_type vt6(0); + const iterator it19 = ms1.insert(it1, vt6); + iterator it20 = it19; + VERIFY( ms1.size() == 9 ); + VERIFY( *it19 == vt6 ); + VERIFY( it19 == ms1.begin() ); + VERIFY( ++it20 == it1 ); + VERIFY( *it20 == *it1 ); + + const value_type vt7(3); + const iterator it21 = ms1.insert(it19, vt7); + iterator it22 = it21; + iterator it23 = it21; + VERIFY( ms1.size() == 10 ); + VERIFY( *it21 == vt7 ); + VERIFY( ++it22 == ms1.end() ); + VERIFY( --it23 == it3 ); + VERIFY( *it23 == *it3 ); + + const value_type vt8(2); + const iterator it24 = ms1.insert(ms1.end(), vt8); + iterator it25 = it24; + iterator it26 = it24; + VERIFY( ms1.size() == 11 ); + VERIFY( *it24 == vt8 ); + VERIFY( ++it25 == it21 ); + VERIFY( --it26 == it3 ); + VERIFY( *it25 == *it21 ); + VERIFY( *it26 == *it3 ); + + const value_type vt9(3); + const iterator it27 = ms1.insert(it3, vt9); + iterator it28 = it27; + iterator it29 = it27; + VERIFY( ms1.size() == 12 ); + VERIFY( *it27 == vt9 ); + VERIFY( ++it28 == it21 ); + VERIFY( --it29 == it24 ); + VERIFY( *it28 == *it21 ); + VERIFY( *it29 == *it24 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/3.cc new file mode 100644 index 000000000..202d2eec0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/3.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + s.insert(rvalstruct(2)); + Set::iterator i = s.insert(rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i == s.begin() || i == i2 ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/4.cc new file mode 100644 index 000000000..eccf18f47 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/4.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(s.begin(), rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i0 = s.insert(s.begin(), rvalstruct(2)); + Set::iterator i1 = s.insert(i0, rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i1).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i1 == s.begin() ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc new file mode 100644 index 000000000..f7d541deb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2005, 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 <set> +#include <testsuite_hooks.h> + +struct T { int i; }; + +// T must be LessThanComparable to pass concept-checks +bool operator<(T l, T r) { return l.i < r.i; } + +int swap_calls; + +namespace std +{ + template<> + void + multiset<T>::swap(multiset<T>&) + { ++swap_calls; } +} + +// Should use multiset specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::multiset<T> A; + std::multiset<T> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use multiset specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + multiset<T> A; + multiset<T> B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc new file mode 100644 index 000000000..81cad5ba5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc @@ -0,0 +1,137 @@ +// 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.3.4 multiset::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef multiset<char, less<char>, my_alloc> my_multiset; + + 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); + + const multiset<char> mset01_ref(title01, title01 + N1); + const multiset<char> mset02_ref(title02, title02 + N2); + const multiset<char> mset03_ref(title03, title03 + N3); + const multiset<char> mset04_ref(title04, title04 + N4); + + my_multiset::size_type size01, size02; + + my_alloc alloc01(1); + + my_multiset mset01(less<char>(), alloc01); + size01 = mset01.size(); + my_multiset mset02(less<char>(), alloc01); + size02 = mset02.size(); + + mset01.swap(mset02); + VERIFY( mset01.size() == size02 ); + VERIFY( mset01.empty() ); + VERIFY( mset02.size() == size01 ); + VERIFY( mset02.empty() ); + + my_multiset mset03(less<char>(), alloc01); + size01 = mset03.size(); + my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); + size02 = mset04.size(); + + mset03.swap(mset04); + VERIFY( mset03.size() == size02 ); + VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); + VERIFY( mset04.size() == size01 ); + VERIFY( mset04.empty() ); + + my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); + size01 = mset05.size(); + my_multiset mset06(title02, title02 + N2, less<char>(), alloc01); + size02 = mset06.size(); + + mset05.swap(mset06); + VERIFY( mset05.size() == size02 ); + VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); + VERIFY( mset06.size() == size01 ); + VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); + + my_multiset mset07(title01, title01 + N1, less<char>(), alloc01); + size01 = mset07.size(); + my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); + size02 = mset08.size(); + + mset07.swap(mset08); + VERIFY( mset07.size() == size02 ); + VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); + VERIFY( mset08.size() == size01 ); + VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); + + my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); + size01 = mset09.size(); + my_multiset mset10(title04, title04 + N4, less<char>(), alloc01); + size02 = mset10.size(); + + mset09.swap(mset10); + VERIFY( mset09.size() == size02 ); + VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); + VERIFY( mset10.size() == size01 ); + VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); + + my_multiset mset11(title04, title04 + N4, less<char>(), alloc01); + size01 = mset11.size(); + my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); + size02 = mset12.size(); + + mset11.swap(mset12); + VERIFY( mset11.size() == size02 ); + VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); + VERIFY( mset12.size() == size01 ); + VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); + + my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); + size01 = mset13.size(); + my_multiset mset14(title03, title03 + N3, less<char>(), alloc01); + size02 = mset14.size(); + + mset13.swap(mset14); + VERIFY( mset13.size() == size02 ); + VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); + VERIFY( mset14.size() == size01 ); + VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc new file mode 100644 index 000000000..0d99bfb42 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc @@ -0,0 +1,166 @@ +// 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.3.4 multiset::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef multiset<char, less<char>, my_alloc> my_multiset; + + 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); + + const multiset<char> mset01_ref(title01, title01 + N1); + const multiset<char> mset02_ref(title02, title02 + N2); + const multiset<char> mset03_ref(title03, title03 + N3); + const multiset<char> mset04_ref(title04, title04 + N4); + + my_multiset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_multiset mset01(less<char>(), alloc01); + size01 = mset01.size(); + personality01 = mset01.get_allocator().get_personality(); + my_multiset mset02(less<char>(), alloc02); + size02 = mset02.size(); + personality02 = mset02.get_allocator().get_personality(); + + mset01.swap(mset02); + VERIFY( mset01.size() == size02 ); + VERIFY( mset01.empty() ); + VERIFY( mset02.size() == size01 ); + VERIFY( mset02.empty() ); + VERIFY( mset01.get_allocator().get_personality() == personality02 ); + VERIFY( mset02.get_allocator().get_personality() == personality01 ); + + my_multiset mset03(less<char>(), alloc02); + size01 = mset03.size(); + personality01 = mset03.get_allocator().get_personality(); + my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); + size02 = mset04.size(); + personality02 = mset04.get_allocator().get_personality(); + + mset03.swap(mset04); + VERIFY( mset03.size() == size02 ); + VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); + VERIFY( mset04.size() == size01 ); + VERIFY( mset04.empty() ); + VERIFY( mset03.get_allocator().get_personality() == personality02 ); + VERIFY( mset04.get_allocator().get_personality() == personality01 ); + + my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); + size01 = mset05.size(); + personality01 = mset05.get_allocator().get_personality(); + my_multiset mset06(title02, title02 + N2, less<char>(), alloc02); + size02 = mset06.size(); + personality02 = mset06.get_allocator().get_personality(); + + mset05.swap(mset06); + VERIFY( mset05.size() == size02 ); + VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); + VERIFY( mset06.size() == size01 ); + VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); + VERIFY( mset05.get_allocator().get_personality() == personality02 ); + VERIFY( mset06.get_allocator().get_personality() == personality01 ); + + my_multiset mset07(title01, title01 + N1, less<char>(), alloc02); + size01 = mset07.size(); + personality01 = mset07.get_allocator().get_personality(); + my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); + size02 = mset08.size(); + personality02 = mset08.get_allocator().get_personality(); + + mset07.swap(mset08); + VERIFY( mset07.size() == size02 ); + VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); + VERIFY( mset08.size() == size01 ); + VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); + VERIFY( mset07.get_allocator().get_personality() == personality02 ); + VERIFY( mset08.get_allocator().get_personality() == personality01 ); + + my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); + size01 = mset09.size(); + personality01 = mset09.get_allocator().get_personality(); + my_multiset mset10(title04, title04 + N4, less<char>(), alloc02); + size02 = mset10.size(); + personality02 = mset10.get_allocator().get_personality(); + + mset09.swap(mset10); + VERIFY( mset09.size() == size02 ); + VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); + VERIFY( mset10.size() == size01 ); + VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); + VERIFY( mset09.get_allocator().get_personality() == personality02 ); + VERIFY( mset10.get_allocator().get_personality() == personality01 ); + + my_multiset mset11(title04, title04 + N4, less<char>(), alloc02); + size01 = mset11.size(); + personality01 = mset11.get_allocator().get_personality(); + my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); + size02 = mset12.size(); + personality02 = mset12.get_allocator().get_personality(); + + mset11.swap(mset12); + VERIFY( mset11.size() == size02 ); + VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); + VERIFY( mset12.size() == size01 ); + VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); + VERIFY( mset11.get_allocator().get_personality() == personality02 ); + VERIFY( mset12.get_allocator().get_personality() == personality01 ); + + my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); + size01 = mset13.size(); + personality01 = mset13.get_allocator().get_personality(); + my_multiset mset14(title03, title03 + N3, less<char>(), alloc02); + size02 = mset14.size(); + personality02 = mset14.get_allocator().get_personality(); + + mset13.swap(mset14); + VERIFY( mset13.size() == size02 ); + VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); + VERIFY( mset14.size() == size01 ); + VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); + VERIFY( mset13.get_allocator().get_personality() == personality02 ); + VERIFY( mset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/operations/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/operations/1.cc new file mode 100644 index 000000000..a54795d65 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/operations/1.cc @@ -0,0 +1,125 @@ +// 2006-11-25 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 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 <set> +#include <testsuite_hooks.h> + +// A few tests for equal_range, in the occasion of libstdc++/29385. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multiset<int> ms0; + typedef multiset<int>::iterator iterator; + pair<iterator, iterator> pp0; + + pp0 = ms0.equal_range(1); + VERIFY( ms0.count(1) == 0 ); + VERIFY( pp0.first == ms0.end() ); + VERIFY( pp0.second == ms0.end() ); + + iterator iter0 = ms0.insert(1); + iterator iter1 = ms0.insert(2); + iterator iter2 = ms0.insert(3); + + pp0 = ms0.equal_range(2); + VERIFY( ms0.count(2) == 1 ); + VERIFY( *pp0.first == 2 ); + VERIFY( *pp0.second == 3 ); + VERIFY( pp0.first == iter1 ); + VERIFY( --pp0.first == iter0 ); + VERIFY( pp0.second == iter2 ); + + ms0.insert(3); + iterator iter3 = ms0.insert(3); + iterator iter4 = ms0.insert(4); + + pp0 = ms0.equal_range(3); + VERIFY( ms0.count(3) == 3 ); + VERIFY( *pp0.first == 3 ); + VERIFY( *pp0.second == 4 ); + VERIFY( pp0.first == iter2 ); + VERIFY( --pp0.first == iter1 ); + VERIFY( pp0.second == iter4 ); + + iterator iter5 = ms0.insert(0); + ms0.insert(1); + ms0.insert(1); + ms0.insert(1); + + pp0 = ms0.equal_range(1); + VERIFY( ms0.count(1) == 4 ); + VERIFY( *pp0.first == 1 ); + VERIFY( *pp0.second == 2 ); + VERIFY( pp0.first == iter0 ); + VERIFY( --pp0.first == iter5 ); + VERIFY( pp0.second == iter1 ); + + iterator iter6 = ms0.insert(5); + ms0.insert(5); + ms0.insert(5); + + pp0 = ms0.equal_range(5); + VERIFY( ms0.count(5) == 3 ); + VERIFY( *pp0.first == 5 ); + VERIFY( pp0.first == iter6 ); + VERIFY( --pp0.first == iter4 ); + VERIFY( pp0.second == ms0.end() ); + + ms0.insert(4); + ms0.insert(4); + ms0.insert(4); + + pp0 = ms0.equal_range(4); + VERIFY( ms0.count(4) == 4 ); + VERIFY( *pp0.first == 4 ); + VERIFY( *pp0.second == 5 ); + VERIFY( pp0.first == iter4 ); + VERIFY( --pp0.first == iter3 ); + VERIFY( pp0.second == iter6 ); + + ms0.insert(0); + iterator iter7 = ms0.insert(0); + ms0.insert(1); + + pp0 = ms0.equal_range(0); + VERIFY( ms0.count(0) == 3 ); + VERIFY( *pp0.first == 0 ); + VERIFY( *pp0.second == 1 ); + VERIFY( pp0.first == iter5 ); + VERIFY( pp0.first == ms0.begin() ); + VERIFY( pp0.second == iter0 ); + + pp0 = ms0.equal_range(1); + VERIFY( ms0.count(1) == 5 ); + VERIFY( *pp0.first == 1 ); + VERIFY( *pp0.second == 2 ); + VERIFY( pp0.first == iter0 ); + VERIFY( --pp0.first == iter7 ); + VERIFY( pp0.second == iter1 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc b/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc new file mode 100644 index 000000000..d3fb95ea2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <set> + +void +test01() +{ + std::multiset<int> ms{1, 2, 3}; + std::begin(ms); + std::end(ms); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/citerators.cc new file mode 100644 index 000000000..bf3aa1644 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <set> +#include <testsuite_containers.h> + +int main() +{ + typedef std::multiset<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/basic.cc new file mode 100644 index 000000000..4525843e1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/basic.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <set> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<value_type> compare_type; + typedef std::multiset<value_type, compare_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..889b1067b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/generation_prohibited.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::less<value_type> compare_type; + typedef std::multiset<value_type, compare_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..b1dd057eb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/exception/propagation_consistent.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<value_type> compare_type; + typedef std::multiset<value_type, compare_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..cdc8db7c8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <set> + +// { dg-do compile } + +template class std::multiset<int>; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..cb522b2e5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <set> + +template class std::multiset<int>; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..11f29c028 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/2.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +template class std::multiset<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..7f6b64040 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <set> + +// { dg-do compile } + +// libstdc++/21770 +template class std::multiset<int, std::less<int>, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..d55064cd1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/explicit_instantiation/4.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::multiset<__gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..959d4a848 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 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/>. + + +// This file tests user specialization of library containers + +#include <set> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Allocator> + class multiset<user_type, Allocator> {}; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/multiset/requirements/typedefs.cc new file mode 100644 index 000000000..7244003c2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <set> + +// Check container for required typedefs. +__gnu_test::types<std::multiset<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc new file mode 100644 index 000000000..0c21b25f9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/members/7161.cc @@ -0,0 +1,47 @@ +// 2002-06-28 pme + +// Copyright (C) 2002, 2004, 2005, 2009, 2010 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.3 container adaptros + +#include <queue> +#include <testsuite_hooks.h> + +// libstdc++/7161 +void +test03() +{ + int data[] = {1, 2, 3}; + std::priority_queue<int> pq; + + for (int i = 0; i < 3; ++i) + pq.push(data[i]); + + pq.top(); + for (int i = 0; i < 2; ++i) + pq.pop(); + + while (!pq.empty()) + pq.pop(); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/moveable.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/moveable.cc new file mode 100644 index 000000000..7e9e9989b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/moveable.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on vector (via swap). If the implementation changed +// this test may begin to fail. + +#include <queue> +#include <utility> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::priority_queue<int> a,b; + a.push(1); + b = std::move(a); + VERIFY( b.size() == 1 && b.top() == 1 && a.size() == 0 ); + + std::priority_queue<int> c(std::move(b)); + VERIFY( c.size() == 1 && c.top() == 1 ); + VERIFY( b.size() == 0 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..bf444ce1a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <queue> + +template class std::priority_queue<int>; diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..54a25271f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers. + +#include <queue> + +template class std::priority_queue<int>; diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/typedefs.cc new file mode 100644 index 000000000..86fcb0c13 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <queue> + +// Check container for required typedefs. +__gnu_test::types<std::priority_queue<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc b/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc new file mode 100644 index 000000000..0e452de31 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/members/7157.cc @@ -0,0 +1,40 @@ +// 2002-06-28 pme + +// Copyright (C) 2002, 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.3 container adaptros + +#include <queue> +#include <testsuite_hooks.h> + +// libstdc++/7157 +void +test01() +{ + std::queue<int> q; + + q.push(1); + q.front(); + q.pop(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/queue/moveable.cc b/libstdc++-v3/testsuite/23_containers/queue/moveable.cc new file mode 100644 index 000000000..3bf55cf31 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/moveable.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on vector (via swap). If the implementation changed +// this test may begin to fail. + +#include <queue> +#include <utility> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::queue<int> a,b; + a.push(1); + b = std::move(a); + VERIFY( b.size() == 1 && b.front() == 1 && a.size() == 0 ); + + std::queue<int> c(std::move(b)); + VERIFY( c.size() == 1 && c.front() == 1 ); + VERIFY( b.size() == 0 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/queue/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/queue/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..31ace6c8c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <queue> + +template class std::queue<int>; diff --git a/libstdc++-v3/testsuite/23_containers/queue/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/queue/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..7daf02999 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers. + +#include <queue> + +template class std::queue<int>; diff --git a/libstdc++-v3/testsuite/23_containers/queue/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/queue/requirements/typedefs.cc new file mode 100644 index 000000000..7563a2cc9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/queue/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <queue> + +// Check container for required typedefs. +__gnu_test::types<std::queue<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/set/14340.cc b/libstdc++-v3/testsuite/23_containers/set/14340.cc new file mode 100644 index 000000000..8539544e6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/14340.cc @@ -0,0 +1,34 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <set> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::set<int> container; + __gnu_test::conversion<container>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/18604.cc b/libstdc++-v3/testsuite/23_containers/set/18604.cc new file mode 100644 index 000000000..a57f95f4b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/18604.cc @@ -0,0 +1,43 @@ +// 2005-05-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include <set> + diff --git a/libstdc++-v3/testsuite/23_containers/set/23781_neg.cc b/libstdc++-v3/testsuite/23_containers/set/23781_neg.cc new file mode 100644 index 000000000..b47b748ec --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/23781_neg.cc @@ -0,0 +1,28 @@ +// 2005-09-10 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2009, 2010 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/>. +// + +// { dg-do compile } + +// libstdc++/23781 +#include <set> +#include <cstddef> + +std::set<int>::iterator it = NULL; // { dg-error "conversion" } +std::set<int>::const_iterator cit = NULL; // { dg-error "conversion" } diff --git a/libstdc++-v3/testsuite/23_containers/set/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/set/capacity/29134.cc new file mode 100644 index 000000000..7d9bccd0f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/capacity/29134.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2006, 2007, 2008, 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.3.3 set capacity + +#include <set> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::set<int> s; + + VERIFY( s.max_size() == + std::allocator<std::_Rb_tree_node<int> >().max_size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/check_construct_destroy.cc b/libstdc++-v3/testsuite/23_containers/set/check_construct_destroy.cc new file mode 100644 index 000000000..6a9bf611c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/check_construct_destroy.cc @@ -0,0 +1,76 @@ +// 2004-07-26 Matt Austern <austern@apple.com> +// +// Copyright (C) 2003, 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 <set> +#include <functional> +#include <iterator> +#include <testsuite_allocator.h> + +using namespace __gnu_test; + +int main() +{ + typedef std::set<int, std::less<int>, tracker_allocator<int> > Container; + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + const int arr10a[10] = { 31, 23, 82, 46, 13, 17, 30, 71, 22, 51 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + Container c; + ok = check_construct_destroy("empty container", 0, 0) && ok; + } + ok = check_construct_destroy("empty container", 0, 0) && ok; + + + tracker_allocator_counter::reset(); + { + Container c(arr10, arr10 + 10); + ok = check_construct_destroy("Construct from range", 10, 0) && ok; + } + ok = check_construct_destroy("Construct from range", 10, 10) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(arr10a[0]); + ok = check_construct_destroy("Insert element", 1, 0) && ok; + } + ok = check_construct_destroy("Insert element", 1, 11) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(arr10a, arr10a+3); + ok = check_construct_destroy("Insert short range", 3, 0) && ok; + } + ok = check_construct_destroy("Insert short range", 3, 13) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(arr10a, arr10a+10); + ok = check_construct_destroy("Insert long range", 10, 0) && ok; + } + ok = check_construct_destroy("Insert long range", 10, 20) && ok; + + return ok ? 0 : 1; +} + diff --git a/libstdc++-v3/testsuite/23_containers/set/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/set/cons/moveable.cc new file mode 100644 index 000000000..9c43e3833 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on set (via swap). If the implementation changed +// this test may begin to fail. + +#include <set> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::set<int> a,b; + a.insert(2); + b.insert(1); + b = std::move(a); + VERIFY(b.find(2) != b.end() && a.find(1) == a.end()); + + std::set<int> c(std::move(b)); + VERIFY( c.find(2) != c.end()); + VERIFY( b.find(2) == b.end()); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/construct1_neg.cc new file mode 100644 index 000000000..424eb8be2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/construct2_neg.cc new file mode 100644 index 000000000..d5819925b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/construct3_neg.cc new file mode 100644 index 000000000..1cc7dd234 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/construct4_neg.cc new file mode 100644 index 000000000..d464aabfb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/insert1_neg.cc new file mode 100644 index 000000000..3192ff959 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/insert2_neg.cc new file mode 100644 index 000000000..d0d16cfb9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/insert3_neg.cc new file mode 100644 index 000000000..9eaf6f82b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/insert4_neg.cc new file mode 100644 index 000000000..c2424d2a3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/set/debug/invalidation/1.cc new file mode 100644 index 000000000..6d5a0f50b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/invalidation/1.cc @@ -0,0 +1,51 @@ +// Set iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::set; +using std::advance; + +bool test = true; + +// Assignment +void test01() +{ + set<int> v1; + set<int> v2; + + v1.insert(17); + + set<int>::iterator start = v1.begin(); + set<int>::iterator finish = v1.end(); + VERIFY(start._M_dereferenceable()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); + + v1 = v2; + VERIFY(start._M_singular()); + VERIFY(!finish._M_dereferenceable() && !finish._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/set/debug/invalidation/2.cc new file mode 100644 index 000000000..2539b03dd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/invalidation/2.cc @@ -0,0 +1,70 @@ +// Set iterator invalidation tests + +// Copyright (C) 2003, 2004, 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 <debug/set> +#include <iterator> +#include <testsuite_hooks.h> + +using __gnu_debug::set; +using std::advance; + +// Erase +void test02() +{ + bool test __attribute__((unused)) = true; + + set<int> v; + for (int i = 0; i < 20; ++i) + v.insert(i); + + // Single element erase (middle) + set<int>::iterator before = v.begin(); + set<int>::iterator at = before; + advance(at, 3); + set<int>::iterator after = at; + ++after; + v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_dereferenceable()); + + // Multiple element erase + before = v.begin(); + at = before; + advance(at, 3); + after = at; + advance(after, 4); + v.erase(at, after); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + set<int>::iterator finish = v.end(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); + VERIFY(!finish._M_singular() && !finish._M_dereferenceable()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/dr130.cc b/libstdc++-v3/testsuite/23_containers/set/dr130.cc new file mode 100644 index 000000000..1dac5628d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/dr130.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } +// 2008-07-22 Edward Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2009, 2010 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 <set> +#include <testsuite_hooks.h> + +// DR 130. Associative erase should return an iterator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + set<int> s0; + typedef set<int>::iterator iterator; + typedef set<int>::const_iterator const_iterator; + typedef pair<iterator, bool> insert_return_type; + + s0.insert(1); + insert_return_type irt1 = s0.insert(2); + insert_return_type irt2 = s0.insert(3); + + iterator pos1 = s0.erase(irt1.first); + VERIFY( pos1 == irt2.first ); + + iterator pos2 = s0.erase(irt2.first); + VERIFY( pos2 == s0.end() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + set<int> s0; + typedef set<int>::iterator iterator; + typedef set<int>::const_iterator const_iterator; + typedef pair<iterator, bool> insert_return_type; + + insert_return_type irt0 = s0.insert(1); + s0.insert(2); + insert_return_type irt2 = s0.insert(3); + insert_return_type irt3 = s0.insert(4); + + iterator pos1 = s0.erase(irt0.first, irt2.first); + VERIFY( pos1 == irt2.first ); + + iterator pos2 = s0.erase(irt2.first, ++irt3.first); + VERIFY( pos2 == s0.end() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/init-list.cc b/libstdc++-v3/testsuite/23_containers/set/init-list.cc new file mode 100644 index 000000000..e0b3d6b95 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/init-list.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <set> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + set<int> m({ 1, 5, 37 }); + VERIFY(m.size() == 3); + VERIFY(m.count(1) == 1); + VERIFY(m.count(5) == 1); + VERIFY(m.count(37) == 1); + VERIFY(m.count(42) == 0); + + m = { 28, 37, 102 }; + VERIFY(m.size() == 3); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 1); + VERIFY(m.count(102) == 1); + VERIFY(m.count(1) == 0); + + m.insert({ 42 }); + VERIFY(m.size() == 4); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 1); + VERIFY(m.count(102) == 1); + VERIFY(m.count(42) == 1); + VERIFY(m.count(1) == 0); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/16728.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/16728.cc new file mode 100644 index 000000000..28376a353 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/16728.cc @@ -0,0 +1,92 @@ +// Copyright (C) 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/>. + + +/* + * The goal with this application is to compare the performance + * between different std::allocator implementations. The results are + * influenced by the underlying allocator in the "C" library, malloc. + */ + +#include <set> +#include <sstream> + +using namespace std; + +typedef int test_type; + +// This can take extremely long on simulators, timing out the test. +// { dg-options "-DITERATIONS=10" { target simulator } } +#ifndef ITERATIONS +#define ITERATIONS 10000 +#endif + +// The number of iterations to be performed. +int iterations = ITERATIONS; + +// The number of values to insert in the container, 32 will cause 5 +// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64) +// This means that all allocations are within _MAX_BYTES = 128 as +// defined in stl_alloc.h for __pool_alloc. Whether or not this +// value is relevant in "the real world" or not I don't know and +// should probably be investigated in more detail. +int insert_values = 128; + +template<typename TestType> + struct value_type : public pair<TestType, TestType> + { + value_type() : pair<TestType, TestType>(0, 0) { } + + inline value_type operator++() { return ++this->first, *this; } + inline operator TestType() const { return this->first; } + }; + +template<typename Container> + void + do_loop() + { + Container obj; + int test_iterations = 0; + value_type<test_type> test_value; + while (test_iterations < iterations) + { + for (int j = 0; j < insert_values; ++j) + obj.insert(obj.end(), ++test_value); + ++test_iterations; + } + } + +template<typename Container> + void + test_container(Container, bool run_threaded = false) + { + do_loop<Container>(); + std::ostringstream comment; + if (run_threaded) + comment << "4-way threaded iterations: " << iterations*4 << '\t'; + else + comment << "iterations: " << iterations << '\t'; + } + +// http://gcc.gnu.org/ml/libstdc++/2001-05/msg00105.html +// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html +int main(void) +{ + typedef less<test_type> compare_type; + test_container(set<test_type, compare_type>()); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/17948.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/17948.cc new file mode 100644 index 000000000..baee1fe8a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/17948.cc @@ -0,0 +1,44 @@ +// 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 <set> +#include <testsuite_hooks.h> + +// libstdc++/17948 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef set<int>::size_type size_type; + + set<int> s; + + s.insert(2); + s.insert(3); + + size_type x = s.erase(3); + + VERIFY( s.size() == 1 ); + VERIFY( x == 1 ); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/51142.cc new file mode 100644 index 000000000..4fb296a95 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <set> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator<(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::set<X>& s, X x) +{ + std::set<X>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/1.cc new file mode 100644 index 000000000..0b2dd3e2a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/1.cc @@ -0,0 +1,83 @@ +// 2005-01-17 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 <set> +#include <testsuite_hooks.h> + +// A few tests for insert with hint, in the occasion of libstdc++/19422 +// and libstdc++/19433. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + set<int> s0, s1; + set<int>::iterator iter1; + + s0.insert(1); + s1.insert(s1.end(), 1); + VERIFY( s0 == s1 ); + + s0.insert(3); + s1.insert(s1.begin(), 3); + VERIFY( s0 == s1 ); + + s0.insert(4); + iter1 = s1.insert(s1.end(), 4); + VERIFY( s0 == s1 ); + + s0.insert(6); + s1.insert(iter1, 6); + VERIFY( s0 == s1 ); + + s0.insert(2); + s1.insert(s1.begin(), 2); + VERIFY( s0 == s1 ); + + s0.insert(7); + s1.insert(s1.end(), 7); + VERIFY( s0 == s1 ); + + s0.insert(5); + s1.insert(s1.find(4), 5); + VERIFY( s0 == s1 ); + + s0.insert(0); + s1.insert(s1.end(), 0); + VERIFY( s0 == s1 ); + + s0.insert(8); + s1.insert(s1.find(3), 8); + VERIFY( s0 == s1 ); + + s0.insert(9); + s1.insert(s1.end(), 9); + VERIFY( s0 == s1 ); + + s0.insert(10); + s1.insert(s1.begin(), 10); + VERIFY( s0 == s1 ); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/2.cc new file mode 100644 index 000000000..31159262b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/2.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + std::pair<Set::iterator, bool> p = s.insert(rvalstruct(1)); + VERIFY( p.second ); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p.first == s.begin() ); + VERIFY( (*p.first).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + std::pair<Set::iterator, bool> p1 = s.insert(rvalstruct(2)); + std::pair<Set::iterator, bool> p2 = s.insert(rvalstruct(2)); + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( s.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (*p1.first).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/3.cc new file mode 100644 index 000000000..03e0d9d6c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/3.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator p = s.insert(s.begin(), rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p == s.begin() ); + VERIFY( (*p).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator p1 = s.insert(s.begin(), rvalstruct(2)); + Set::iterator p2 = s.insert(p1, rvalstruct(2)); + VERIFY( s.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( (*p1).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc new file mode 100644 index 000000000..789185f8f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2005, 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 <set> +#include <testsuite_hooks.h> + +struct T { int i; }; + +// T must be LessThanComparable to pass concept-checks +bool operator<(T l, T r) { return l.i < r.i; } + +int swap_calls; + +namespace std +{ + template<> + void + set<T>::swap(set<T>&) + { ++swap_calls; } +} + +// Should use set specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::set<T> A; + std::set<T> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use set specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + set<T> A; + set<T> B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc new file mode 100644 index 000000000..8899b6dae --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc @@ -0,0 +1,137 @@ +// 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.3.3 set::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef set<char, less<char>, my_alloc> my_set; + + 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); + + const set<char> set01_ref(title01, title01 + N1); + const set<char> set02_ref(title02, title02 + N2); + const set<char> set03_ref(title03, title03 + N3); + const set<char> set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1); + + my_set set01(less<char>(), alloc01); + size01 = set01.size(); + my_set set02(less<char>(), alloc01); + size02 = set02.size(); + + set01.swap(set02); + VERIFY( set01.size() == size02 ); + VERIFY( set01.empty() ); + VERIFY( set02.size() == size01 ); + VERIFY( set02.empty() ); + + my_set set03(less<char>(), alloc01); + size01 = set03.size(); + my_set set04(title02, title02 + N2, less<char>(), alloc01); + size02 = set04.size(); + + set03.swap(set04); + VERIFY( set03.size() == size02 ); + VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) ); + VERIFY( set04.size() == size01 ); + VERIFY( set04.empty() ); + + my_set set05(title01, title01 + N1, less<char>(), alloc01); + size01 = set05.size(); + my_set set06(title02, title02 + N2, less<char>(), alloc01); + size02 = set06.size(); + + set05.swap(set06); + VERIFY( set05.size() == size02 ); + VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) ); + VERIFY( set06.size() == size01 ); + VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) ); + + my_set set07(title01, title01 + N1, less<char>(), alloc01); + size01 = set07.size(); + my_set set08(title03, title03 + N3, less<char>(), alloc01); + size02 = set08.size(); + + set07.swap(set08); + VERIFY( set07.size() == size02 ); + VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) ); + VERIFY( set08.size() == size01 ); + VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) ); + + my_set set09(title03, title03 + N3, less<char>(), alloc01); + size01 = set09.size(); + my_set set10(title04, title04 + N4, less<char>(), alloc01); + size02 = set10.size(); + + set09.swap(set10); + VERIFY( set09.size() == size02 ); + VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) ); + VERIFY( set10.size() == size01 ); + VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) ); + + my_set set11(title04, title04 + N4, less<char>(), alloc01); + size01 = set11.size(); + my_set set12(title01, title01 + N1, less<char>(), alloc01); + size02 = set12.size(); + + set11.swap(set12); + VERIFY( set11.size() == size02 ); + VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) ); + VERIFY( set12.size() == size01 ); + VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) ); + + my_set set13(title03, title03 + N3, less<char>(), alloc01); + size01 = set13.size(); + my_set set14(title03, title03 + N3, less<char>(), alloc01); + size02 = set14.size(); + + set13.swap(set14); + VERIFY( set13.size() == size02 ); + VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) ); + VERIFY( set14.size() == size01 ); + VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc new file mode 100644 index 000000000..5f192293d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc @@ -0,0 +1,166 @@ +// 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.3.3 set::swap + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef set<char, less<char>, my_alloc> my_set; + + 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); + + const set<char> set01_ref(title01, title01 + N1); + const set<char> set02_ref(title02, title02 + N2); + const set<char> set03_ref(title03, title03 + N3); + const set<char> set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_set set01(less<char>(), alloc01); + size01 = set01.size(); + personality01 = set01.get_allocator().get_personality(); + my_set set02(less<char>(), alloc02); + size02 = set02.size(); + personality02 = set02.get_allocator().get_personality(); + + set01.swap(set02); + VERIFY( set01.size() == size02 ); + VERIFY( set01.empty() ); + VERIFY( set02.size() == size01 ); + VERIFY( set02.empty() ); + VERIFY( set01.get_allocator().get_personality() == personality02 ); + VERIFY( set02.get_allocator().get_personality() == personality01 ); + + my_set set03(less<char>(), alloc02); + size01 = set03.size(); + personality01 = set03.get_allocator().get_personality(); + my_set set04(title02, title02 + N2, less<char>(), alloc01); + size02 = set04.size(); + personality02 = set04.get_allocator().get_personality(); + + set03.swap(set04); + VERIFY( set03.size() == size02 ); + VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) ); + VERIFY( set04.size() == size01 ); + VERIFY( set04.empty() ); + VERIFY( set03.get_allocator().get_personality() == personality02 ); + VERIFY( set04.get_allocator().get_personality() == personality01 ); + + my_set set05(title01, title01 + N1, less<char>(), alloc01); + size01 = set05.size(); + personality01 = set05.get_allocator().get_personality(); + my_set set06(title02, title02 + N2, less<char>(), alloc02); + size02 = set06.size(); + personality02 = set06.get_allocator().get_personality(); + + set05.swap(set06); + VERIFY( set05.size() == size02 ); + VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) ); + VERIFY( set06.size() == size01 ); + VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) ); + VERIFY( set05.get_allocator().get_personality() == personality02 ); + VERIFY( set06.get_allocator().get_personality() == personality01 ); + + my_set set07(title01, title01 + N1, less<char>(), alloc02); + size01 = set07.size(); + personality01 = set07.get_allocator().get_personality(); + my_set set08(title03, title03 + N3, less<char>(), alloc01); + size02 = set08.size(); + personality02 = set08.get_allocator().get_personality(); + + set07.swap(set08); + VERIFY( set07.size() == size02 ); + VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) ); + VERIFY( set08.size() == size01 ); + VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) ); + VERIFY( set07.get_allocator().get_personality() == personality02 ); + VERIFY( set08.get_allocator().get_personality() == personality01 ); + + my_set set09(title03, title03 + N3, less<char>(), alloc01); + size01 = set09.size(); + personality01 = set09.get_allocator().get_personality(); + my_set set10(title04, title04 + N4, less<char>(), alloc02); + size02 = set10.size(); + personality02 = set10.get_allocator().get_personality(); + + set09.swap(set10); + VERIFY( set09.size() == size02 ); + VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) ); + VERIFY( set10.size() == size01 ); + VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) ); + VERIFY( set09.get_allocator().get_personality() == personality02 ); + VERIFY( set10.get_allocator().get_personality() == personality01 ); + + my_set set11(title04, title04 + N4, less<char>(), alloc02); + size01 = set11.size(); + personality01 = set11.get_allocator().get_personality(); + my_set set12(title01, title01 + N1, less<char>(), alloc01); + size02 = set12.size(); + personality02 = set12.get_allocator().get_personality(); + + set11.swap(set12); + VERIFY( set11.size() == size02 ); + VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) ); + VERIFY( set12.size() == size01 ); + VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) ); + VERIFY( set11.get_allocator().get_personality() == personality02 ); + VERIFY( set12.get_allocator().get_personality() == personality01 ); + + my_set set13(title03, title03 + N3, less<char>(), alloc01); + size01 = set13.size(); + personality01 = set13.get_allocator().get_personality(); + my_set set14(title03, title03 + N3, less<char>(), alloc02); + size02 = set14.size(); + personality02 = set14.get_allocator().get_personality(); + + set13.swap(set14); + VERIFY( set13.size() == size02 ); + VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) ); + VERIFY( set14.size() == size01 ); + VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) ); + VERIFY( set13.get_allocator().get_personality() == personality02 ); + VERIFY( set14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/operations/1.cc b/libstdc++-v3/testsuite/23_containers/set/operations/1.cc new file mode 100644 index 000000000..7b828930a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/operations/1.cc @@ -0,0 +1,126 @@ +// 2006-11-25 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 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 <set> +#include <testsuite_hooks.h> + +// A few tests for equal_range, in the occasion of libstdc++/29385. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + set<int> s0; + typedef set<int>::iterator iterator; + typedef pair<iterator, bool> insert_return_type; + pair<iterator, iterator> pp0; + + pp0 = s0.equal_range(1); + VERIFY( s0.count(1) == 0 ); + VERIFY( pp0.first == s0.end() ); + VERIFY( pp0.second == s0.end() ); + + insert_return_type irt0 = s0.insert(1); + insert_return_type irt1 = s0.insert(2); + insert_return_type irt2 = s0.insert(3); + + pp0 = s0.equal_range(2); + VERIFY( s0.count(2) == 1 ); + VERIFY( *pp0.first == 2 ); + VERIFY( *pp0.second == 3 ); + VERIFY( pp0.first == irt1.first ); + VERIFY( --pp0.first == irt0.first ); + VERIFY( pp0.second == irt2.first ); + + s0.insert(3); + insert_return_type irt3 = s0.insert(3); + insert_return_type irt4 = s0.insert(4); + + pp0 = s0.equal_range(3); + VERIFY( s0.count(3) == 1 ); + VERIFY( *pp0.first == 3 ); + VERIFY( *pp0.second == 4 ); + VERIFY( pp0.first == irt2.first ); + VERIFY( --pp0.first == irt1.first ); + VERIFY( pp0.second == irt4.first ); + + insert_return_type irt5 = s0.insert(0); + s0.insert(1); + s0.insert(1); + s0.insert(1); + + pp0 = s0.equal_range(1); + VERIFY( s0.count(1) == 1 ); + VERIFY( *pp0.first == 1 ); + VERIFY( *pp0.second == 2 ); + VERIFY( pp0.first == irt0.first ); + VERIFY( --pp0.first == irt5.first ); + VERIFY( pp0.second == irt1.first ); + + insert_return_type irt6 = s0.insert(5); + s0.insert(5); + s0.insert(5); + + pp0 = s0.equal_range(5); + VERIFY( s0.count(5) == 1 ); + VERIFY( *pp0.first == 5 ); + VERIFY( pp0.first == irt6.first ); + VERIFY( --pp0.first == irt4.first ); + VERIFY( pp0.second == s0.end() ); + + s0.insert(4); + s0.insert(4); + s0.insert(4); + + pp0 = s0.equal_range(4); + VERIFY( s0.count(4) == 1 ); + VERIFY( *pp0.first == 4 ); + VERIFY( *pp0.second == 5 ); + VERIFY( pp0.first == irt4.first ); + VERIFY( --pp0.first == irt3.first ); + VERIFY( pp0.second == irt6.first ); + + s0.insert(0); + insert_return_type irt7 = s0.insert(0); + s0.insert(1); + + pp0 = s0.equal_range(0); + VERIFY( s0.count(0) == 1 ); + VERIFY( *pp0.first == 0 ); + VERIFY( *pp0.second == 1 ); + VERIFY( pp0.first == irt5.first ); + VERIFY( pp0.first == s0.begin() ); + VERIFY( pp0.second == irt0.first ); + + pp0 = s0.equal_range(1); + VERIFY( s0.count(1) == 1 ); + VERIFY( *pp0.first == 1 ); + VERIFY( *pp0.second == 2 ); + VERIFY( pp0.first == irt0.first ); + VERIFY( --pp0.first == irt7.first ); + VERIFY( pp0.second == irt1.first ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/operators/1_neg.cc b/libstdc++-v3/testsuite/23_containers/set/operators/1_neg.cc new file mode 100644 index 000000000..babd6db2b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/operators/1_neg.cc @@ -0,0 +1,43 @@ +// { dg-do compile } + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, +// 2008, 2009, 2010 +// 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.3.4 template class multiset negative tests +// 2000-09-07 bgarcia@laurelnetworks.com + +#include <set> +#include <string> + +// libstdc++/86: map & set iterator comparisons are not type-safe +void test01() +{ + bool test __attribute__((unused)) = true; + + std::set<unsigned int> setByIndex; + std::set<std::string> setByName; + + std::set<unsigned int>::iterator itr(setByIndex.begin()); + + // NB: it's not setByIndex!! + test &= itr != setByName.end(); // { dg-error "no" } + test &= itr == setByName.end(); // { dg-error "no" } +} + +// { dg-excess-errors "" } diff --git a/libstdc++-v3/testsuite/23_containers/set/range_access.cc b/libstdc++-v3/testsuite/23_containers/set/range_access.cc new file mode 100644 index 000000000..b1c33b773 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <set> + +void +test01() +{ + std::set<int> s{1, 2, 3}; + std::begin(s); + std::end(s); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/citerators.cc new file mode 100644 index 000000000..20dd8b9f1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <set> +#include <testsuite_containers.h> + +int main() +{ + typedef std::set<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/exception/basic.cc new file mode 100644 index 000000000..d9146e30c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/exception/basic.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <set> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<value_type> compare_type; + typedef std::set<value_type, compare_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..0536b99ac --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/exception/generation_prohibited.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::less<value_type> compare_type; + typedef std::set<value_type, compare_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..dccfd3a5f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/exception/propagation_consistent.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::less<value_type> compare_type; + typedef std::set<value_type, compare_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..0b8550590 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <set> + +// { dg-do compile } + +template class std::set<int>; diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..e957decf0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <set> + +template class std::set<int>; diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..181e9ce6a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/2.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +template class std::set<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..1cc37c731 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <set> + +// { dg-do compile } + +// libstdc++/21770 +template class std::set<int, std::less<int>, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..2bbe97667 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/explicit_instantiation/4.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::set<__gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..d57aec669 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 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/>. + + +// This file tests user specialization of library containers + +#include <set> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Allocator> + class set<user_type, Allocator> {}; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/set/requirements/typedefs.cc new file mode 100644 index 000000000..0581e49ec --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <set> + +// Check container for required typedefs. +__gnu_test::types<std::set<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/stack/members/7158.cc b/libstdc++-v3/testsuite/23_containers/stack/members/7158.cc new file mode 100644 index 000000000..925f03604 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/stack/members/7158.cc @@ -0,0 +1,40 @@ +// 2002-06-28 pme + +// Copyright (C) 2002, 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.3 container adaptros + +#include <stack> +#include <testsuite_hooks.h> + +// libstdc++/7158 +void +test02() +{ + std::stack<int> st; + + st.push(1); + st.top() = 42; + st.pop(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/stack/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/stack/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..dbdef0007 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/stack/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 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/>. + + +// This file tests explicit instantiation of library containers. + +#include <stack> + +template class std::stack<int>; diff --git a/libstdc++-v3/testsuite/23_containers/stack/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/stack/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..93307bcf4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/stack/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers. + +#include <stack> + +template class std::stack<int>; diff --git a/libstdc++-v3/testsuite/23_containers/stack/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/stack/requirements/typedefs.cc new file mode 100644 index 000000000..d0f56e5d6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/stack/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <stack> + +// Check container for required typedefs. +__gnu_test::types<std::stack<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/moveable.cc new file mode 100644 index 000000000..ab73be1e7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on map (via swap). If the implementation changed +// this test may begin to fail. + +#include <unordered_map> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_map<int, int> a,b; + a[2]=0; + b[1]=0; + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_map<int, int> c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct1_neg.cc new file mode 100644 index 000000000..31961f7ce --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct2_neg.cc new file mode 100644 index 000000000..560651a46 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct3_neg.cc new file mode 100644 index 000000000..7d57272f1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct4_neg.cc new file mode 100644 index 000000000..e37cab21a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/construct4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert1_neg.cc new file mode 100644 index 000000000..f3d06bf74 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert2_neg.cc new file mode 100644 index 000000000..09d55e190 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert3_neg.cc new file mode 100644 index 000000000..41af75917 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert4_neg.cc new file mode 100644 index 000000000..6239431bb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/insert4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::unordered_map<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc new file mode 100644 index 000000000..82b67f4ee --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++0x" } +// 2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008, 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 <unordered_map> +#include <stdexcept> +#include <testsuite_hooks.h> + +// DR 761. unordered_map needs an at() member function. +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::unordered_map<int, double> map_type; + + { + map_type m; + m[0] = 1.5; + + double& rd = m.at(0); + VERIFY( rd == 1.5 ); + try + { + m.at(1); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } + } + + { + map_type m; + m[1] = 2.5; + const map_type cm(m); + + const double& crd = cm.at(1); + VERIFY( crd == 2.5 ); + try + { + cm.at(0); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc new file mode 100644 index 000000000..f9b74e08c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/1.cc @@ -0,0 +1,129 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef Map::iterator iterator; + typedef Map::const_iterator const_iterator; + typedef Map::value_type value_type; + + Map m1; + + m1.insert(value_type("because to why", 1)); + m1.insert(value_type("the stockholm syndrome", 2)); + m1.insert(value_type("a cereous night", 3)); + m1.insert(value_type("eeilo", 4)); + m1.insert(value_type("protean", 5)); + m1.insert(value_type("the way you are when", 6)); + m1.insert(value_type("tillsammans", 7)); + m1.insert(value_type("umbra/penumbra", 8)); + m1.insert(value_type("belonging (no longer mix)", 9)); + m1.insert(value_type("one line behind", 10)); + VERIFY( m1.size() == 10 ); + + VERIFY( m1.erase("eeilo") == 1 ); + VERIFY( m1.size() == 9 ); + iterator it1 = m1.find("eeilo"); + VERIFY( it1 == m1.end() ); + + VERIFY( m1.erase("tillsammans") == 1 ); + VERIFY( m1.size() == 8 ); + iterator it2 = m1.find("tillsammans"); + VERIFY( it2 == m1.end() ); + + // Must work (see DR 526) + iterator it3 = m1.find("belonging (no longer mix)"); + VERIFY( it3 != m1.end() ); + VERIFY( m1.erase(it3->first) == 1 ); + VERIFY( m1.size() == 7 ); + it3 = m1.find("belonging (no longer mix)"); + VERIFY( it3 == m1.end() ); + + VERIFY( !m1.erase("abra") ); + VERIFY( m1.size() == 7 ); + + VERIFY( !m1.erase("eeilo") ); + VERIFY( m1.size() == 7 ); + + VERIFY( m1.erase("because to why") == 1 ); + VERIFY( m1.size() == 6 ); + iterator it4 = m1.find("because to why"); + VERIFY( it4 == m1.end() ); + + iterator it5 = m1.find("umbra/penumbra"); + iterator it6 = m1.find("one line behind"); + VERIFY( it5 != m1.end() ); + VERIFY( it6 != m1.end() ); + + VERIFY( m1.find("the stockholm syndrome") != m1.end() ); + VERIFY( m1.find("a cereous night") != m1.end() ); + VERIFY( m1.find("the way you are when") != m1.end() ); + VERIFY( m1.find("a cereous night") != m1.end() ); + + VERIFY( m1.erase(it5->first) == 1 ); + VERIFY( m1.size() == 5 ); + it5 = m1.find("umbra/penumbra"); + VERIFY( it5 == m1.end() ); + + VERIFY( m1.erase(it6->first) == 1 ); + VERIFY( m1.size() == 4 ); + it6 = m1.find("one line behind"); + VERIFY( it6 == m1.end() ); + + iterator it7 = m1.begin(); + iterator it8 = it7; + ++it8; + iterator it9 = it8; + ++it9; + + VERIFY( m1.erase(it8->first) == 1 ); + VERIFY( m1.size() == 3 ); + VERIFY( ++it7 == it9 ); + + iterator it10 = it9; + ++it10; + iterator it11 = it10; + + VERIFY( m1.erase(it9->first) == 1 ); + VERIFY( m1.size() == 2 ); + VERIFY( ++it10 == m1.end() ); + + VERIFY( m1.erase(m1.begin()) != m1.end() ); + VERIFY( m1.size() == 1 ); + VERIFY( m1.begin() == it11 ); + + VERIFY( m1.erase(m1.begin()->first) == 1 ); + VERIFY( m1.size() == 0 ); + VERIFY( m1.begin() == m1.end() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/erase/24061-map.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/24061-map.cc new file mode 100644 index 000000000..87ab474a8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/24061-map.cc @@ -0,0 +1,105 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef Map::iterator iterator; + typedef Map::const_iterator const_iterator; + typedef Map::value_type value_type; + + Map m1; + + m1.insert(value_type("all the love in the world", 1)); + m1.insert(value_type("you know what you are?", 2)); + m1.insert(value_type("the collector", 3)); + m1.insert(value_type("the hand that feeds", 4)); + m1.insert(value_type("love is not enough", 5)); + m1.insert(value_type("every day is exactly the same", 6)); + m1.insert(value_type("with teeth", 7)); + m1.insert(value_type("only", 8)); + m1.insert(value_type("getting smaller", 9)); + m1.insert(value_type("sunspots", 10)); + VERIFY( m1.size() == 10 ); + + iterator it1 = m1.begin(); + ++it1; + iterator it2 = it1; + ++it2; + iterator it3 = m1.erase(it1); + VERIFY( m1.size() == 9 ); + VERIFY( it3 == it2 ); + VERIFY( *it3 == *it2 ); + + iterator it4 = m1.begin(); + ++it4; + ++it4; + ++it4; + iterator it5 = it4; + ++it5; + ++it5; + iterator it6 = m1.erase(it4, it5); + VERIFY( m1.size() == 7 ); + VERIFY( it6 == it5 ); + VERIFY( *it6 == *it5 ); + + const_iterator it7 = m1.begin(); + ++it7; + ++it7; + ++it7; + const_iterator it8 = it7; + ++it8; + const_iterator it9 = m1.erase(it7); + VERIFY( m1.size() == 6 ); + VERIFY( it9 == it8 ); + VERIFY( *it9 == *it8 ); + + const_iterator it10 = m1.begin(); + ++it10; + const_iterator it11 = it10; + ++it11; + ++it11; + ++it11; + ++it11; + const_iterator it12 = m1.erase(it10, it11); + VERIFY( m1.size() == 2 ); + VERIFY( it12 == it11 ); + VERIFY( *it12 == *it11 ); + VERIFY( ++it12 == m1.end() ); + + iterator it13 = m1.erase(m1.begin(), m1.end()); + VERIFY( m1.size() == 0 ); + VERIFY( it13 == it12 ); + VERIFY( it13 == m1.begin() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/51142.cc new file mode 100644 index 000000000..eab637df2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <unordered_map> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator==(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::unordered_map<X, int>& s, X x) +{ + std::unordered_map<X, int>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/hash_policy/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/hash_policy/dr1189.cc new file mode 100644 index 000000000..f89d5f199 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/hash_policy/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <testsuite_hooks.h> + +// DR 1189. Awkward interface for changing the number of buckets +// in an unordered associative container +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unordered_map<int, double> m1; + m1.reserve(10); + VERIFY( m1.bucket_count() >= 10 ); + + m1.reserve(100); + VERIFY( m1.bucket_count() >= 100 ); + + std::unordered_map<int, double> m2(100); + VERIFY( m2.bucket_count() >= 100 ); + + m2.reserve(1000); + VERIFY( m2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/init-list.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/init-list.cc new file mode 100644 index 000000000..262fa0eb9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/init-list.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <unordered_map> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + unordered_map<int,double> m({ { 1, 1.0 }, { 2, 2.0 }, { 42, 237.0 } }); + VERIFY(m.size() == 3); + VERIFY(m[1] == 1.0); + VERIFY(m[2] == 2.0); + VERIFY(m[42] == 237.0); + + m = { {5, 55.0}, { 6, 66.0 } }; + VERIFY(m.size() == 2); + VERIFY(m[5] == 55.0); + VERIFY(m[6] == 66.0); + + m.insert({ { 7, 77.0 }, { 8, 88.0 } }); + VERIFY(m.size() == 4); + VERIFY(m[5] == 55.0); + VERIFY(m[6] == 66.0); + VERIFY(m[7] == 77.0); + VERIFY(m[8] == 88.0); + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/24061-map.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/24061-map.cc new file mode 100644 index 000000000..d9a187870 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/24061-map.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef Map::iterator iterator; + typedef Map::const_iterator const_iterator; + typedef Map::value_type value_type; + + Map m1; + + iterator it1 = m1.insert(m1.begin(), + value_type("all the love in the world", 1)); + VERIFY( m1.size() == 1 ); + VERIFY( *it1 == value_type("all the love in the world", 1) ); + + const_iterator cit1(it1); + const_iterator cit2 = m1.insert(cit1, + value_type("you know what you are?", 2)); + VERIFY( m1.size() == 2 ); + VERIFY( cit2 != cit1 ); + VERIFY( *cit2 == value_type("you know what you are?", 2) ); + + iterator it2 = m1.insert(it1, value_type("all the love in the world", 3)); + VERIFY( m1.size() == 2 ); + VERIFY( it2 == it1 ); + VERIFY( *it2 == value_type("all the love in the world", 1) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/array_syntax.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/array_syntax.cc new file mode 100644 index 000000000..91f58799a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/array_syntax.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Array version of insert + +#include <string> +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + + Map m; + VERIFY( m.empty() ); + + m["red"] = 17; + VERIFY( m.size() == 1 ); + VERIFY( m.begin()->first == "red" ); + VERIFY( m.begin()->second == 17 ); + VERIFY( m["red"] == 17 ); + + m["blue"] = 9; + VERIFY( m.size() == 2 ); + VERIFY( m["blue"] == 9 ); + + m["red"] = 5; + VERIFY( m.size() == 2 ); + VERIFY( m["red"] == 5 ); + VERIFY( m["blue"] == 9 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/array_syntax_move.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/array_syntax_move.cc new file mode 100644 index 000000000..b0729e327 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/array_syntax_move.cc @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Array version of insert + +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_map<rvalstruct, rvalstruct> Map; + + Map m; + VERIFY( m.empty() ); + + m[rvalstruct(1)] = rvalstruct(17); + VERIFY( m.size() == 1 ); + VERIFY( (m.begin()->first).val == 1 ); + VERIFY( (m.begin()->second).val == 17 ); + VERIFY( m[rvalstruct(1)].val == 17 ); + + m[rvalstruct(2)] = rvalstruct(9); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(2)].val == 9 ); + + m[rvalstruct(1)] = rvalstruct(5); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(1)].val == 5 ); + VERIFY( m[rvalstruct(2)].val == 9 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_range.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_range.cc new file mode 100644 index 000000000..5e5298c04 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_range.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// range insert + +#include <string> +#include <iterator> +#include <algorithm> +#include <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + Pair A[5] = + { + Pair("red", 5), + Pair("green", 9), + Pair("blue", 3), + Pair("cyan", 8), + Pair("magenta", 7) + }; + + m.insert(A+0, A+5); + VERIFY(m.size() == 5); + VERIFY(std::distance(m.begin(), m.end()) == 5); + + VERIFY(m["red"] == 5); + VERIFY(m["green"] == 9); + VERIFY(m["blue"] == 3); + VERIFY(m["cyan"] == 8); + VERIFY(m["magenta"] == 7); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + Pair A[9] = + { + Pair("red", 5), + Pair("green", 9), + Pair("red", 19), + Pair("blue", 3), + Pair("blue", 60), + Pair("cyan", 8), + Pair("magenta", 7), + Pair("blue", 99), + Pair("green", 33) + }; + + m.insert(A+0, A+9); + VERIFY(m.size() == 5); + VERIFY(std::distance(m.begin(), m.end()) == 5); + + VERIFY(m["red"] == 5); + VERIFY(m["green"] == 9); + VERIFY(m["blue"] == 3); + VERIFY(m["cyan"] == 8); + VERIFY(m["magenta"] == 7); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single.cc new file mode 100644 index 000000000..3905e26c9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <string> +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair("abcde", 3)); + VERIFY(p.second); + VERIFY(m.size() == 1); + VERIFY(std::distance(m.begin(), m.end()) == 1); + VERIFY(p.first == m.begin()); + VERIFY(p.first->first == "abcde"); + VERIFY(p.first->second == 3); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_map<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair("abcde", 3)); + std::pair<Map::iterator, bool> p2 = m.insert(Pair("abcde", 7)); + + VERIFY(p1.second); + VERIFY(!p2.second); + VERIFY(m.size() == 1); + VERIFY(p1.first == p2.first); + VERIFY(p1.first->first == "abcde"); + VERIFY(p2.first->second == 3); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single_move-1.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single_move-1.cc new file mode 100644 index 000000000..45186ce45 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single_move-1.cc @@ -0,0 +1,76 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair(1, rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( p.first->first == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair(2, rvalstruct(3))); + std::pair<Map::iterator, bool> p2 = m.insert(Pair(2, rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( p1.first->first == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single_move-2.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single_move-2.cc new file mode 100644 index 000000000..76b6bba00 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/map_single_move-2.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( (p.first->first).val == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair(rvalstruct(2), + rvalstruct(3))); + std::pair<Map::iterator, bool> p2 = m.insert(Pair(rvalstruct(2), + rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (p1.first->first).val == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/operators/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/operators/1.cc new file mode 100644 index 000000000..f5e68dea7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/operators/1.cc @@ -0,0 +1,169 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-03-25 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::pair<const int, int> Pair; + std::unordered_map<int, int> um1, um2; + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -1)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(2, -1)); + um2.insert(Pair(2, -1)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -1)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(3, -3)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um2.insert(Pair(3, -3)); + VERIFY( (um1 == um2) ); + VERIFY( !(um1 != um2) ); + + um2.clear(); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.clear(); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(2, -2)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(2, -2)); + um2.insert(Pair(1, -1)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(3, -3)); + um2.insert(Pair(4, -4)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(4, -4)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um2.insert(Pair(3, -3)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -1)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(4, -4)); + um2.insert(Pair(4, -4)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.clear(); + um2.clear(); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -2)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.clear(); + um2.clear(); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -1)); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(2, -2)); + um2.insert(Pair(2, -3)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(2, -3)); + um2.insert(Pair(2, -2)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.clear(); + um2.clear(); + VERIFY( um1 == um2 ); + VERIFY( !(um1 != um2) ); + + um1.insert(Pair(2, -2)); + um2.insert(Pair(2, -3)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -1)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(2, -3)); + um2.insert(Pair(2, -2)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -1)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + um1.insert(Pair(1, -1)); + um2.insert(Pair(1, -2)); + VERIFY( um1 != um2 ); + VERIFY( !(um1 == um2) ); + + const std::unordered_map<int, int> cum1(um1), cum2(um2); + VERIFY( cum1 != cum2 ); + VERIFY( !(cum1 == cum2) ); + VERIFY( cum1 != um2 ); + VERIFY( !(um1 == cum2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/profile/hash_map.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/profile/hash_map.cc new file mode 100644 index 000000000..7939a35e3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/profile/hash_map.cc @@ -0,0 +1,22 @@ +// { dg-options "-Wno-deprecated" } +/* testing the gcc instrumented */ + +#include <ext/hash_map> +using namespace std; +using __gnu_cxx::hash_map; + +int main() +{ + hash_map <int, int> *tmp; + + for (int j=1; j<=10; j++) + { + tmp = new hash_map<int, int>; + // Insert more than default item + for (int i=0; i<10000*j; i++) { + (*tmp)[i]= i; + } + delete tmp; + } +} + diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/profile/unordered.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/profile/unordered.cc new file mode 100644 index 000000000..93b506e98 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/profile/unordered.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +/* testing the gcc instrumented */ + +#include <unordered_map> +#include <unordered_set> +using std::unordered_map; +using std::unordered_set; + +void test_unordered_set() +{ + // Test for unordered set + unordered_set <int> *tmp2; + tmp2 = new unordered_set<int>; + tmp2->insert(1); + delete tmp2; +} +void test_unordered_map() +{ + unordered_map <int, int> *tmp; + for (int i=0; i<20; i++) + { + tmp = new unordered_map<int, int>(i+2); + // Insert more than default item + for (int j=0; j<10000; j++) { + (*tmp)[j]= j; + } + + delete tmp; + } + + tmp = new unordered_map<int, int>; + + // Insert more than default item + for (int i=0; i<150000; i++) { +// (*tmp)[i] = i; + (*tmp).insert(unordered_map<int, int>::value_type(i, i)); + } + + (*tmp).erase(1); + delete tmp; +} +int main() +{ + test_unordered_set(); + test_unordered_map(); +} + diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc new file mode 100644 index 000000000..1555c4896 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <unordered_map> + +void +test01() +{ + std::unordered_map<int, double> um{{1, 1.0}, {2, 2.0}, {3, 3.0}}; + std::begin(um); + std::end(um); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/citerators.cc new file mode 100644 index 000000000..a00635a56 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/citerators.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <unordered_map> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_map<int, int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/cliterators.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/cliterators.cc new file mode 100644 index 000000000..3cad0a16a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/cliterators.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-06-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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 <unordered_map> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_map<int, int> test_type; + typedef typename test_type::value_type value_type; + value_type v(1, 1); + __gnu_test::forward_members_unordered<test_type> test(v); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_container.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_container.cc new file mode 100644 index 000000000..632070996 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_container.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <string> +#include <debug/unordered_map> + +using namespace __gnu_debug; + +using std::allocator; +using std::equal_to; +using std::hash; +using std::pair; +using std::string; + +template class unordered_map<string, float>; +template class unordered_map<string, int, + hash<string>, equal_to<string>, + allocator<pair<const string, int> > >; +template class unordered_map<string, float, + hash<string>, equal_to<string>, + allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_mode.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_mode.cc new file mode 100644 index 000000000..8b2fe14ca --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_mode.cc @@ -0,0 +1,30 @@ +// NB: This issue affected only debug-mode. + +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <unordered_map> + +//PR libstdc++/35922 +int main() +{ + std::unordered_map<int, int> m; +} + diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/basic.cc new file mode 100644 index 000000000..bcad65f8a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/basic.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_map> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_map<value_type, value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..7ed320198 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/generation_prohibited.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_map<value_type, value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..7bb555f41 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/exception/propagation_consistent.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_map<value_type, value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..9027fdcc1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/1.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_map> + +template class std::unordered_map<int, float>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..7f4e05138 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/2.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2009, 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::NonDefaultConstructible inst_type; +typedef __gnu_test::NonDefaultConstructible_hash hash_type; + +// N.B. We cannot instantiate with mapped_type == NonDefaultConstructible +// because of 23.5.1.2. +template class std::unordered_map<inst_type, double, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..695fa6f58 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/3.cc @@ -0,0 +1,24 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_map> + +using namespace std; +template class unordered_map<int, int, hash<int>, equal_to<int>, allocator<char>>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..37b57b371 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/4.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::OverloadedAddress inst_type; +typedef __gnu_test::OverloadedAddress_hash hash_type; + +// libstdc++/41792 +template class std::unordered_map<inst_type, inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/typedefs.cc new file mode 100644 index 000000000..9b978cebc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <unordered_map> + +// Check container for required typedefs. +__gnu_test::types<std::unordered_map<int, long> > t; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/moveable.cc new file mode 100644 index 000000000..145054b8f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on multimap (via swap). If the implementation changed +// this test may begin to fail. + +#include <unordered_map> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multimap<int, int> a,b; + a.insert(std::make_pair(2,0)); + b.insert(std::make_pair(1,0)); + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_multimap<int, int> c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct1_neg.cc new file mode 100644 index 000000000..7a17e4c0e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct2_neg.cc new file mode 100644 index 000000000..8f2c1a6d9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct3_neg.cc new file mode 100644 index 000000000..3fb4be737 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct4_neg.cc new file mode 100644 index 000000000..000745e75 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/construct4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert1_neg.cc new file mode 100644 index 000000000..e36a0a170 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert2_neg.cc new file mode 100644 index 000000000..04a488be1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert3_neg.cc new file mode 100644 index 000000000..1c7f60f93 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert4_neg.cc new file mode 100644 index 000000000..988c31293 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/insert4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_map> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::unordered_multimap<int, int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc new file mode 100644 index 000000000..095157265 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/1.cc @@ -0,0 +1,130 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Mmap; + typedef Mmap::iterator iterator; + typedef Mmap::const_iterator const_iterator; + typedef Mmap::value_type value_type; + + Mmap mm1; + + mm1.insert(value_type("because to why", 1)); + mm1.insert(value_type("the stockholm syndrome", 2)); + mm1.insert(value_type("a cereous night", 3)); + mm1.insert(value_type("eeilo", 4)); + mm1.insert(value_type("protean", 5)); + mm1.insert(value_type("the way you are when", 6)); + mm1.insert(value_type("tillsammans", 7)); + mm1.insert(value_type("umbra/penumbra", 8)); + mm1.insert(value_type("belonging (no longer mix)", 9)); + mm1.insert(value_type("one line behind", 10)); + mm1.insert(value_type("because to why", 11)); + VERIFY( mm1.size() == 11 ); + + VERIFY( mm1.erase("eeilo") == 1 ); + VERIFY( mm1.size() == 10 ); + iterator it1 = mm1.find("eeilo"); + VERIFY( it1 == mm1.end() ); + + VERIFY( mm1.erase("tillsammans") == 1 ); + VERIFY( mm1.size() == 9 ); + iterator it2 = mm1.find("tillsammans"); + VERIFY( it2 == mm1.end() ); + + // Must work (see DR 526) + iterator it3 = mm1.find("belonging (no longer mix)"); + VERIFY( it3 != mm1.end() ); + VERIFY( mm1.erase(it3->first) == 1 ); + VERIFY( mm1.size() == 8 ); + it3 = mm1.find("belonging (no longer mix)"); + VERIFY( it3 == mm1.end() ); + + VERIFY( !mm1.erase("abra") ); + VERIFY( mm1.size() == 8 ); + + VERIFY( !mm1.erase("eeilo") ); + VERIFY( mm1.size() == 8 ); + + VERIFY( mm1.erase("because to why") == 2 ); + VERIFY( mm1.size() == 6 ); + iterator it4 = mm1.find("because to why"); + VERIFY( it4 == mm1.end() ); + + iterator it5 = mm1.find("umbra/penumbra"); + iterator it6 = mm1.find("one line behind"); + VERIFY( it5 != mm1.end() ); + VERIFY( it6 != mm1.end() ); + + VERIFY( mm1.find("the stockholm syndrome") != mm1.end() ); + VERIFY( mm1.find("a cereous night") != mm1.end() ); + VERIFY( mm1.find("the way you are when") != mm1.end() ); + VERIFY( mm1.find("a cereous night") != mm1.end() ); + + VERIFY( mm1.erase(it5->first) == 1 ); + VERIFY( mm1.size() == 5 ); + it5 = mm1.find("umbra/penumbra"); + VERIFY( it5 == mm1.end() ); + + VERIFY( mm1.erase(it6->first) == 1 ); + VERIFY( mm1.size() == 4 ); + it6 = mm1.find("one line behind"); + VERIFY( it6 == mm1.end() ); + + iterator it7 = mm1.begin(); + iterator it8 = it7; + ++it8; + iterator it9 = it8; + ++it9; + + VERIFY( mm1.erase(it8->first) == 1 ); + VERIFY( mm1.size() == 3 ); + VERIFY( ++it7 == it9 ); + + iterator it10 = it9; + ++it10; + iterator it11 = it10; + + VERIFY( mm1.erase(it9->first) == 1 ); + VERIFY( mm1.size() == 2 ); + VERIFY( ++it10 == mm1.end() ); + + VERIFY( mm1.erase(mm1.begin()) != mm1.end() ); + VERIFY( mm1.size() == 1 ); + VERIFY( mm1.begin() == it11 ); + + VERIFY( mm1.erase(mm1.begin()->first) == 1 ); + VERIFY( mm1.size() == 0 ); + VERIFY( mm1.begin() == mm1.end() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/24061-multimap.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/24061-multimap.cc new file mode 100644 index 000000000..545d08278 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/24061-multimap.cc @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Mmap; + typedef Mmap::iterator iterator; + typedef Mmap::const_iterator const_iterator; + typedef Mmap::value_type value_type; + + Mmap mm1; + + mm1.insert(value_type("all the love in the world", 1)); + mm1.insert(value_type("you know what you are?", 2)); + mm1.insert(value_type("the collector", 3)); + mm1.insert(value_type("the hand that feeds", 4)); + mm1.insert(value_type("love is not enough", 5)); + mm1.insert(value_type("every day is exactly the same", 6)); + mm1.insert(value_type("with teeth", 7)); + mm1.insert(value_type("only", 8)); + mm1.insert(value_type("getting smaller", 9)); + mm1.insert(value_type("sunspots", 10)); + + mm1.insert(value_type("you know what you are?", 5)); + mm1.insert(value_type("the collector", 6)); + mm1.insert(value_type("the hand that feeds", 7)); + VERIFY( mm1.size() == 13 ); + + iterator it1 = mm1.begin(); + ++it1; + iterator it2 = it1; + ++it2; + iterator it3 = mm1.erase(it1); + VERIFY( mm1.size() == 12 ); + VERIFY( it3 == it2 ); + VERIFY( *it3 == *it2 ); + + iterator it4 = mm1.begin(); + ++it4; + ++it4; + ++it4; + iterator it5 = it4; + ++it5; + ++it5; + iterator it6 = mm1.erase(it4, it5); + VERIFY( mm1.size() == 10 ); + VERIFY( it6 == it5 ); + VERIFY( *it6 == *it5 ); + + const_iterator it7 = mm1.begin(); + ++it7; + ++it7; + ++it7; + const_iterator it8 = it7; + ++it8; + const_iterator it9 = mm1.erase(it7); + VERIFY( mm1.size() == 9 ); + VERIFY( it9 == it8 ); + VERIFY( *it9 == *it8 ); + + const_iterator it10 = mm1.begin(); + ++it10; + const_iterator it11 = it10; + ++it11; + ++it11; + ++it11; + ++it11; + const_iterator it12 = mm1.erase(it10, it11); + VERIFY( mm1.size() == 5 ); + VERIFY( it12 == it11 ); + VERIFY( *it12 == *it11 ); + + iterator it13 = mm1.erase(mm1.begin(), mm1.end()); + VERIFY( mm1.size() == 0 ); + VERIFY( it13 == mm1.end() ); + VERIFY( it13 == mm1.begin() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51142.cc new file mode 100644 index 000000000..678aa5dd9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <unordered_map> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator==(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::unordered_multimap<X, int>& s, X x) +{ + std::unordered_multimap<X, int>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/hash_policy/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/hash_policy/dr1189.cc new file mode 100644 index 000000000..57e5f7da7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/hash_policy/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <testsuite_hooks.h> + +// DR 1189. Awkward interface for changing the number of buckets +// in an unordered associative container +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multimap<int, double> mm1; + mm1.reserve(10); + VERIFY( mm1.bucket_count() >= 10 ); + + mm1.reserve(100); + VERIFY( mm1.bucket_count() >= 100 ); + + std::unordered_map<int, double> mm2(100); + VERIFY( mm2.bucket_count() >= 100 ); + + mm2.reserve(1000); + VERIFY( mm2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/init-list.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/init-list.cc new file mode 100644 index 000000000..d7ebbf16d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/init-list.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <set> +#include <unordered_map> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + typedef unordered_multimap<int,double> Container; + typedef Container::const_iterator iterator; + typedef pair<iterator,iterator> itpair; + + Container m({ { 1, 1.0 }, { 1, 2.0 }, { 1, 237.0 } }); + VERIFY(m.size() == 3); + itpair ip = m.equal_range(1); + VERIFY(distance(ip.first, ip.second) == 3); + set<double> s = { 1.0, 2.0, 237.0 }; + for (iterator i = ip.first; i != ip.second; ++i) + s.erase (i->second); + VERIFY(s.empty()); + + m = { {5, 55.0}, { 5, 66.0 }, { 42, 4242.0 } }; + VERIFY(m.size() == 3); + ip = m.equal_range(5); + VERIFY(distance(ip.first, ip.second) == 2); + s = { 55.0, 66.0 }; + for (iterator i = ip.first; i != ip.second; ++i) + s.erase (i->second); + VERIFY(s.empty()); + + m.insert({ { 7, 77.0 }, { 7, 88.0 } }); + VERIFY(m.size() == 5); + VERIFY(m.count(5) == 2); + VERIFY(m.count(42) == 1); + VERIFY(m.count(7) == 2); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc new file mode 100644 index 000000000..136580662 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_map> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Mmap; + typedef Mmap::iterator iterator; + typedef Mmap::const_iterator const_iterator; + typedef Mmap::value_type value_type; + + Mmap mm1; + + iterator it1 = mm1.insert(mm1.begin(), + value_type("all the love in the world", 1)); + VERIFY( mm1.size() == 1 ); + VERIFY( *it1 == value_type("all the love in the world", 1) ); + + const_iterator cit1(it1); + const_iterator cit2 = mm1.insert(cit1, + value_type("you know what you are?", 2)); + VERIFY( mm1.size() == 2 ); + VERIFY( cit2 != cit1 ); + VERIFY( *cit2 == value_type("you know what you are?", 2) ); + + iterator it2 = mm1.insert(it1, value_type("all the love in the world", 3)); + VERIFY( mm1.size() == 3 ); + VERIFY( it2 != it1 ); + VERIFY( *it2 == value_type("all the love in the world", 3) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_range.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_range.cc new file mode 100644 index 000000000..b7f405b76 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_range.cc @@ -0,0 +1,91 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// range insert + +#include <string> +#include <iterator> +#include <algorithm> +#include <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + Pair A[5] = + { + Pair("red", 5), + Pair("green", 9), + Pair("blue", 3), + Pair("cyan", 8), + Pair("magenta", 7) + }; + + m.insert(A+0, A+5); + VERIFY(m.size() == 5); + VERIFY(std::distance(m.begin(), m.end()) == 5); + + for (int i = 0; i < 5; ++i) + VERIFY(std::find(m.begin(), m.end(), A[i]) != m.end()); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + Pair A[9] = + { + Pair("red", 5), + Pair("green", 9), + Pair("red", 19), + Pair("blue", 3), + Pair("blue", 60), + Pair("cyan", 8), + Pair("magenta", 7), + Pair("blue", 99), + Pair("green", 33) + }; + + m.insert(A+0, A+9); + VERIFY(m.size() == 9); + VERIFY(std::distance(m.begin(), m.end()) == 9); + + for (int i = 0; i < 9; ++i) + VERIFY(std::find(m.begin(), m.end(), A[i]) != m.end()); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single.cc new file mode 100644 index 000000000..1864098f5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single.cc @@ -0,0 +1,76 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <string> +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + Map::iterator i = m.insert(Pair("abcde", 3)); + VERIFY(m.size() == 1); + VERIFY(std::distance(m.begin(), m.end()) == 1); + VERIFY(i == m.begin()); + VERIFY(i->first == "abcde"); + VERIFY(i->second == 3); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap<std::string, int> Map; + typedef std::pair<const std::string, int> Pair; + + Map m; + VERIFY(m.empty()); + + m.insert(Pair("abcde", 3)); + m.insert(Pair("abcde", 7)); + + VERIFY(m.size() == 2); + VERIFY(std::distance(m.begin(), m.end()) == 2); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY(i1->first == "abcde"); + VERIFY(i2->first == "abcde"); + VERIFY((i1->second == 3 && i2->second == 7) || + (i1->second == 7 && i2->second == 3)); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single_move-1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single_move-1.cc new file mode 100644 index 000000000..4c933069c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single_move-1.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(2, rvalstruct(3))); + m.insert(Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( ((i1->second).val == 3 && (i2->second).val == 7) + || ((i1->second).val == 7 && (i2->second).val == 3) ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single_move-2.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single_move-2.cc new file mode 100644 index 000000000..e9008b461 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/multimap_single_move-2.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <iterator> +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( ((i1->second).val == 3 && (i2->second).val == 7) + || ((i1->second).val == 7 && (i2->second).val == 3) ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/operators/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/operators/1.cc new file mode 100644 index 000000000..f6e21f8b8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/operators/1.cc @@ -0,0 +1,192 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-03-25 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <unordered_map> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::pair<const int, int> Pair; + std::unordered_multimap<int, int> umm1, umm2; + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(2, -1)); + umm2.insert(Pair(2, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(3, -3)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm2.insert(Pair(3, -3)); + VERIFY( (umm1 == umm2) ); + VERIFY( !(umm1 != umm2) ); + + umm2.clear(); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.clear(); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(2, -2)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(2, -2)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(3, -3)); + umm2.insert(Pair(4, -4)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(4, -4)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm2.insert(Pair(3, -3)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(4, -4)); + umm2.insert(Pair(4, -4)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.clear(); + umm2.clear(); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -2)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.clear(); + umm2.clear(); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(2, -2)); + umm2.insert(Pair(2, -3)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(2, -3)); + umm2.insert(Pair(2, -2)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.clear(); + umm2.clear(); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(2, -2)); + umm2.insert(Pair(2, -3)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(2, -3)); + umm2.insert(Pair(2, -2)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + umm1.insert(Pair(1, -1)); + umm2.insert(Pair(1, -2)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(3, -3)); + umm2.insert(Pair(3, -3)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(3, -4)); + umm2.insert(Pair(3, -3)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(3, -3)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm1.insert(Pair(1, -2)); + umm2.insert(Pair(1, -1)); + VERIFY( umm1 != umm2 ); + VERIFY( !(umm1 == umm2) ); + + umm2.insert(Pair(3, -4)); + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + const std::unordered_multimap<int, int> cumm1(umm1), cumm2(umm2); + VERIFY( cumm1 == cumm2 ); + VERIFY( !(cumm1 != cumm2) ); + VERIFY( cumm1 == umm2 ); + VERIFY( !(umm1 != cumm2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/operators/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/operators/2.cc new file mode 100644 index 000000000..1121dbc52 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/operators/2.cc @@ -0,0 +1,63 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-03-25 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <unordered_map> +#include <algorithm> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::pair<const int, int> Pair; + std::unordered_multimap<int, int> umm1, umm2; + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + + int second1[] = { -1, -2, -3, -4, -5 }; + int second2[] = { -1, -2, -3, -4, -5 }; + const unsigned size = sizeof(second1) / sizeof(int); + + for (unsigned perm1 = 0; perm1 < 120; ++perm1) + { + umm1.clear(); + std::next_permutation(second1, second1 + size); + for (unsigned i1 = 0; i1 < size; ++i1) + umm1.insert(Pair(0, second1[i1])); + + for (unsigned perm2 = 0; perm2 < 120; ++perm2) + { + umm2.clear(); + std::next_permutation(second2, second2 + size); + for (unsigned i2 = 0; i2 < size; ++i2) + umm2.insert(Pair(0, second2[i2])); + + VERIFY( umm1 == umm2 ); + VERIFY( !(umm1 != umm2) ); + } + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc new file mode 100644 index 000000000..bfc8ac1c4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <unordered_map> + +void +test01() +{ + std::unordered_multimap<int, double> umm{{1, 1.0}, {2, 2.0}, {3, 3.0}}; + std::begin(umm); + std::end(umm); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/citerators.cc new file mode 100644 index 000000000..736220b73 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <unordered_map> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_multimap<int, int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/cliterators.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/cliterators.cc new file mode 100644 index 000000000..612787cc7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/cliterators.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-06-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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 <unordered_map> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_multimap<int, int> test_type; + typedef typename test_type::value_type value_type; + value_type v(1, 1); + __gnu_test::forward_members_unordered<test_type> test(v); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/debug.cc new file mode 100644 index 000000000..95814ca7b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/debug.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <string> +#include <debug/unordered_map> + +using namespace __gnu_debug; + +using std::string; + +template class unordered_multimap<string, float>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/basic.cc new file mode 100644 index 000000000..c695f9c1a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/basic.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_map> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_multimap<value_type, value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..9426e9d44 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/generation_prohibited.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_multimap<value_type, value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..921c54812 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/exception/propagation_consistent.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_map> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_multimap<value_type, value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..863562db8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/1.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_map> + +template class std::unordered_multimap<int, float>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..2eef3715d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/2.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::NonDefaultConstructible inst_type; +typedef __gnu_test::NonDefaultConstructible_hash hash_type; +template class std::unordered_multimap<inst_type, inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..5085f6110 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/3.cc @@ -0,0 +1,24 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_map> + +using namespace std; +template class unordered_multimap<int, int, hash<int>, equal_to<int>, allocator<char>>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..d92fdc5b3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/4.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_map> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::OverloadedAddress inst_type; +typedef __gnu_test::OverloadedAddress_hash hash_type; + +// libstdc++/41792 +template class std::unordered_multimap<inst_type, inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/typedefs.cc new file mode 100644 index 000000000..eb1b9157a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <unordered_map> + +// Check container for required typedefs. +__gnu_test::types<std::unordered_multimap<int, long> > t; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/moveable.cc new file mode 100644 index 000000000..93ae4e30b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on set (via swap). If the implementation changed +// this test may begin to fail. + +#include <unordered_set> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multiset<int> a,b; + a.insert(2); + b.insert(1); + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_multiset<int> c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct1_neg.cc new file mode 100644 index 000000000..7d8989074 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct2_neg.cc new file mode 100644 index 000000000..ea6857aa2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct3_neg.cc new file mode 100644 index 000000000..20a465962 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct4_neg.cc new file mode 100644 index 000000000..4fbb4fad6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/construct4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert1_neg.cc new file mode 100644 index 000000000..c65c6083d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert2_neg.cc new file mode 100644 index 000000000..6496624ee --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert3_neg.cc new file mode 100644 index 000000000..b12fe5764 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert4_neg.cc new file mode 100644 index 000000000..0f2acea40 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/insert4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::unordered_multiset<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc new file mode 100644 index 000000000..327dc4bd0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/1.cc @@ -0,0 +1,129 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<std::string> Mset; + typedef Mset::iterator iterator; + typedef Mset::const_iterator const_iterator; + + Mset ms1; + + ms1.insert("because to why"); + ms1.insert("the stockholm syndrome"); + ms1.insert("a cereous night"); + ms1.insert("eeilo"); + ms1.insert("protean"); + ms1.insert("the way you are when"); + ms1.insert("tillsammans"); + ms1.insert("umbra/penumbra"); + ms1.insert("belonging (no longer mix)"); + ms1.insert("one line behind"); + ms1.insert("because to why"); + VERIFY( ms1.size() == 11 ); + + VERIFY( ms1.erase("eeilo") == 1 ); + VERIFY( ms1.size() == 10 ); + iterator it1 = ms1.find("eeilo"); + VERIFY( it1 == ms1.end() ); + + VERIFY( ms1.erase("tillsammans") == 1 ); + VERIFY( ms1.size() == 9 ); + iterator it2 = ms1.find("tillsammans"); + VERIFY( it2 == ms1.end() ); + + // Must work (see DR 526) + iterator it3 = ms1.find("belonging (no longer mix)"); + VERIFY( it3 != ms1.end() ); + VERIFY( ms1.erase(*it3) == 1 ); + VERIFY( ms1.size() == 8 ); + it3 = ms1.find("belonging (no longer mix)"); + VERIFY( it3 == ms1.end() ); + + VERIFY( !ms1.erase("abra") ); + VERIFY( ms1.size() == 8 ); + + VERIFY( !ms1.erase("eeilo") ); + VERIFY( ms1.size() == 8 ); + + VERIFY( ms1.erase("because to why") == 2 ); + VERIFY( ms1.size() == 6 ); + iterator it4 = ms1.find("because to why"); + VERIFY( it4 == ms1.end() ); + + iterator it5 = ms1.find("umbra/penumbra"); + iterator it6 = ms1.find("one line behind"); + VERIFY( it5 != ms1.end() ); + VERIFY( it6 != ms1.end() ); + + VERIFY( ms1.find("the stockholm syndrome") != ms1.end() ); + VERIFY( ms1.find("a cereous night") != ms1.end() ); + VERIFY( ms1.find("the way you are when") != ms1.end() ); + VERIFY( ms1.find("a cereous night") != ms1.end() ); + + VERIFY( ms1.erase(*it5) == 1 ); + VERIFY( ms1.size() == 5 ); + it5 = ms1.find("umbra/penumbra"); + VERIFY( it5 == ms1.end() ); + + VERIFY( ms1.erase(*it6) == 1 ); + VERIFY( ms1.size() == 4 ); + it6 = ms1.find("one line behind"); + VERIFY( it6 == ms1.end() ); + + iterator it7 = ms1.begin(); + iterator it8 = it7; + ++it8; + iterator it9 = it8; + ++it9; + + VERIFY( ms1.erase(*it8) == 1 ); + VERIFY( ms1.size() == 3 ); + VERIFY( ++it7 == it9 ); + + iterator it10 = it9; + ++it10; + iterator it11 = it10; + + VERIFY( ms1.erase(*it9) == 1 ); + VERIFY( ms1.size() == 2 ); + VERIFY( ++it10 == ms1.end() ); + + VERIFY( ms1.erase(ms1.begin()) != ms1.end() ); + VERIFY( ms1.size() == 1 ); + VERIFY( ms1.begin() == it11 ); + + VERIFY( ms1.erase(*ms1.begin()) == 1 ); + VERIFY( ms1.size() == 0 ); + VERIFY( ms1.begin() == ms1.end() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/24061-multiset.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/24061-multiset.cc new file mode 100644 index 000000000..c5eea6eee --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/24061-multiset.cc @@ -0,0 +1,107 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<std::string> Mset; + typedef Mset::iterator iterator; + typedef Mset::const_iterator const_iterator; + + Mset ms1; + + ms1.insert("all the love in the world"); + ms1.insert("you know what you are?"); + ms1.insert("the collector"); + ms1.insert("the hand that feeds"); + ms1.insert("love is not enough"); + ms1.insert("every day is exactly the same"); + ms1.insert("with teeth"); + ms1.insert("only"); + ms1.insert("getting smaller"); + ms1.insert("sunspots"); + + ms1.insert("the hand that feeds"); + ms1.insert("love is not enough"); + ms1.insert("every day is exactly the same"); + VERIFY( ms1.size() == 13 ); + + iterator it1 = ms1.begin(); + ++it1; + iterator it2 = it1; + ++it2; + iterator it3 = ms1.erase(it1); + VERIFY( ms1.size() == 12 ); + VERIFY( it3 == it2 ); + VERIFY( *it3 == *it2 ); + + iterator it4 = ms1.begin(); + ++it4; + ++it4; + ++it4; + iterator it5 = it4; + ++it5; + ++it5; + iterator it6 = ms1.erase(it4, it5); + VERIFY( ms1.size() == 10 ); + VERIFY( it6 == it5 ); + VERIFY( *it6 == *it5 ); + + const_iterator it7 = ms1.begin(); + ++it7; + ++it7; + ++it7; + const_iterator it8 = it7; + ++it8; + const_iterator it9 = ms1.erase(it7); + VERIFY( ms1.size() == 9 ); + VERIFY( it9 == it8 ); + VERIFY( *it9 == *it8 ); + + const_iterator it10 = ms1.begin(); + ++it10; + const_iterator it11 = it10; + ++it11; + ++it11; + ++it11; + ++it11; + const_iterator it12 = ms1.erase(it10, it11); + VERIFY( ms1.size() == 5 ); + VERIFY( it12 == it11 ); + VERIFY( *it12 == *it11 ); + + iterator it13 = ms1.erase(ms1.begin(), ms1.end()); + VERIFY( ms1.size() == 0 ); + VERIFY( it13 == ms1.end() ); + VERIFY( it13 == ms1.begin() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/51142.cc new file mode 100644 index 000000000..4db6af0fa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <unordered_set> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator==(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::unordered_multiset<X>& s, X x) +{ + std::unordered_multiset<X>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/hash_policy/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/hash_policy/dr1189.cc new file mode 100644 index 000000000..59232a35a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/hash_policy/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <testsuite_hooks.h> + +// DR 1189. Awkward interface for changing the number of buckets +// in an unordered associative container +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multiset<int> ms1; + ms1.reserve(10); + VERIFY( ms1.bucket_count() >= 10 ); + + ms1.reserve(100); + VERIFY( ms1.bucket_count() >= 100 ); + + std::unordered_multiset<int> ms2(100); + VERIFY( ms2.bucket_count() >= 100 ); + + ms2.reserve(1000); + VERIFY( ms2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/init-list.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/init-list.cc new file mode 100644 index 000000000..41c7ac712 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/init-list.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <unordered_set> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + unordered_multiset<int> m({ 1, 5, 5, 37 }); + VERIFY(m.size() == 4); + VERIFY(m.count(1) == 1); + VERIFY(m.count(5) == 2); + VERIFY(m.count(37) == 1); + VERIFY(m.count(42) == 0); + + m = { 28, 37, 37, 37, 102 }; + VERIFY(m.size() == 5); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 3); + VERIFY(m.count(102) == 1); + VERIFY(m.count(1) == 0); + + m.insert({ 42, 42 }); + VERIFY(m.size() == 7); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 3); + VERIFY(m.count(102) == 1); + VERIFY(m.count(42) == 2); + VERIFY(m.count(1) == 0); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc new file mode 100644 index 000000000..6d8b34d3e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<std::string> Mset; + typedef Mset::iterator iterator; + typedef Mset::const_iterator const_iterator; + + Mset ms1; + + iterator it1 = ms1.insert(ms1.begin(), "all the love in the world"); + VERIFY( ms1.size() == 1 ); + VERIFY( *it1 == "all the love in the world" ); + + const_iterator cit1(it1); + const_iterator cit2 = ms1.insert(cit1, "you know what you are?"); + VERIFY( ms1.size() == 2 ); + VERIFY( cit2 != cit1 ); + VERIFY( *cit2 == "you know what you are?" ); + + iterator it2 = ms1.insert(it1, "all the love in the world"); + VERIFY( ms1.size() == 3 ); + VERIFY( it2 != it1 ); + VERIFY( *it2 == "all the love in the world" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_range.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_range.cc new file mode 100644 index 000000000..571346fd5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_range.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// range insert + +#include <string> +#include <iterator> +#include <algorithm> +#include <unordered_set> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<std::string> Set; + Set s; + VERIFY(s.empty()); + + const int N = 10; + const std::string A[N] = { "red", "green", "blue", "violet", "cyan", + "magenta", "yellow", "orange", "pink", "gray" }; + + s.insert(A+0, A+N); + VERIFY(s.size() == static_cast<unsigned int>(N)); + VERIFY(std::distance(s.begin(), s.end()) == N); + + for (int i = 0; i < N; ++i) { + std::string str = A[i]; + Set::iterator it = std::find(s.begin(), s.end(), str); + VERIFY(it != s.end()); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<int> Set; + Set s; + VERIFY(s.empty()); + + const int N = 8; + const int A[N] = { 3, 7, 4, 8, 2, 4, 6, 7 }; + + s.insert(A+0, A+N); + VERIFY(s.size() == static_cast<unsigned int>(N)); + VERIFY(std::distance(s.begin(), s.end()) == N); + + VERIFY(std::count(s.begin(), s.end(), 2) == 1); + VERIFY(std::count(s.begin(), s.end(), 3) == 1); + VERIFY(std::count(s.begin(), s.end(), 4) == 2); + VERIFY(std::count(s.begin(), s.end(), 6) == 1); + VERIFY(std::count(s.begin(), s.end(), 7) == 2); + VERIFY(std::count(s.begin(), s.end(), 8) == 1); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single.cc new file mode 100644 index 000000000..f275e9a9b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <string> +#include <iterator> +#include <unordered_set> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<std::string> Set; + Set s; + VERIFY(s.empty()); + + Set::iterator i = s.insert("abcde"); + VERIFY(s.size() == 1); + VERIFY(std::distance(s.begin(), s.end()) == 1); + VERIFY(i == s.begin()); + VERIFY(*i == "abcde"); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multiset<std::string> Set; + Set s; + VERIFY(s.empty()); + + s.insert("abcde"); + Set::iterator i = s.insert("abcde"); + VERIFY(s.size() == 2); + VERIFY(std::distance(s.begin(), s.end()) == 2); + VERIFY(*i == "abcde"); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY(i == s.begin() || i == i2); + VERIFY(*(s.begin()) == "abcde" && *i2 == "abcde"); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single_move.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single_move.cc new file mode 100644 index 000000000..14b8e1681 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/multiset_single_move.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <iterator> +#include <unordered_set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + s.insert(rvalstruct(2)); + Set::iterator i = s.insert(rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i == s.begin() || i == i2 ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/operators/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/operators/1.cc new file mode 100644 index 000000000..3e3b1c762 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/operators/1.cc @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-03-25 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <unordered_set> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multiset<int> ums1, ums2; + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(1); + ums2.insert(1); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(2); + ums2.insert(2); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(1); + ums2.insert(1); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(3); + VERIFY( ums1 != ums2 ); + VERIFY( !(ums1 == ums2) ); + + ums2.insert(3); + VERIFY( (ums1 == ums2) ); + VERIFY( !(ums1 != ums2) ); + + ums2.clear(); + VERIFY( ums1 != ums2 ); + VERIFY( !(ums1 == ums2) ); + + ums1.clear(); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(1); + ums2.insert(2); + VERIFY( ums1 != ums2 ); + VERIFY( !(ums1 == ums2) ); + + ums1.insert(2); + ums2.insert(1); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(3); + ums2.insert(4); + VERIFY( ums1 != ums2 ); + VERIFY( !(ums1 == ums2) ); + + ums1.insert(4); + VERIFY( ums1 != ums2 ); + VERIFY( !(ums1 == ums2) ); + + ums2.insert(3); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(1); + ums2.insert(1); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + ums1.insert(4); + ums2.insert(4); + VERIFY( ums1 == ums2 ); + VERIFY( !(ums1 != ums2) ); + + const std::unordered_multiset<int> cums1(ums1), cums2(ums2); + VERIFY( cums1 == cums2 ); + VERIFY( !(cums1 != cums2) ); + VERIFY( cums1 == ums2 ); + VERIFY( !(ums1 != cums2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc new file mode 100644 index 000000000..ac0fdaa2c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <unordered_set> + +void +test01() +{ + std::unordered_multiset<int> ums{1, 2, 3}; + std::begin(ums); + std::end(ums); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/citerators.cc new file mode 100644 index 000000000..6731848fe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <unordered_set> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_multiset<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/cliterators.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/cliterators.cc new file mode 100644 index 000000000..c9db47ce5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/cliterators.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-06-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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 <unordered_set> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_multiset<int> test_type; + typedef typename test_type::value_type value_type; + value_type v(1); + __gnu_test::forward_members_unordered<test_type> test(v); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/debug.cc new file mode 100644 index 000000000..f7774948d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/debug.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <string> +#include <debug/unordered_set> + +using namespace __gnu_debug; + +template class unordered_multiset<int>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/basic.cc new file mode 100644 index 000000000..b0344e844 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/basic.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_set> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_multiset<value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..a0d8abb54 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/generation_prohibited.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_multiset<value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..b0303c14d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/exception/propagation_consistent.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_multiset<value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..a8fbbd081 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/1.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_set> + +template class std::unordered_multiset<int>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..5764e924e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/2.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::NonDefaultConstructible inst_type; +typedef __gnu_test::NonDefaultConstructible_hash hash_type; +template class std::unordered_multiset<inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..faf119ca2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/3.cc @@ -0,0 +1,24 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_set> + +using namespace std; +template class unordered_multiset<int, hash<int>, equal_to<int>, allocator<char>>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..618402643 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/4.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::OverloadedAddress inst_type; +typedef __gnu_test::OverloadedAddress_hash hash_type; + +// libstdc++/41792 +template class std::unordered_multiset<inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/typedefs.cc new file mode 100644 index 000000000..7e65e3a21 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <unordered_set> + +// Check container for required typedefs. +__gnu_test::types<std::unordered_multiset<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/moveable.cc new file mode 100644 index 000000000..29277cfec --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/moveable.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on set (via swap). If the implementation changed +// this test may begin to fail. + +#include <unordered_set> +#include <utility> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_set<int> a,b; + a.insert(2); + b.insert(1); + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_set<int> c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct1_neg.cc new file mode 100644 index 000000000..e37e5209d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct2_neg.cc new file mode 100644 index 000000000..90e5d55a4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct3_neg.cc new file mode 100644 index 000000000..e7222a9c2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct4_neg.cc new file mode 100644 index 000000000..8eb030429 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/construct4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert1_neg.cc new file mode 100644 index 000000000..ab6942cca --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert1_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert2_neg.cc new file mode 100644 index 000000000..81be39da9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert2_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert3_neg.cc new file mode 100644 index 000000000..2d3b7e472 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert3_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert4_neg.cc new file mode 100644 index 000000000..96d6a2a05 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/insert4_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-options "-std=gnu++0x" } +// { dg-do run { xfail *-*-* } } + +#include <debug/unordered_set> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::unordered_set<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc new file mode 100644 index 000000000..8f59773d8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/1.cc @@ -0,0 +1,128 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <string> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_set<std::string> Set; + typedef Set::iterator iterator; + typedef Set::const_iterator const_iterator; + + Set s1; + + s1.insert("because to why"); + s1.insert("the stockholm syndrome"); + s1.insert("a cereous night"); + s1.insert("eeilo"); + s1.insert("protean"); + s1.insert("the way you are when"); + s1.insert("tillsammans"); + s1.insert("umbra/penumbra"); + s1.insert("belonging (no longer mix)"); + s1.insert("one line behind"); + VERIFY( s1.size() == 10 ); + + VERIFY( s1.erase("eeilo") == 1 ); + VERIFY( s1.size() == 9 ); + iterator it1 = s1.find("eeilo"); + VERIFY( it1 == s1.end() ); + + VERIFY( s1.erase("tillsammans") == 1 ); + VERIFY( s1.size() == 8 ); + iterator it2 = s1.find("tillsammans"); + VERIFY( it2 == s1.end() ); + + // Must work (see DR 526) + iterator it3 = s1.find("belonging (no longer mix)"); + VERIFY( it3 != s1.end() ); + VERIFY( s1.erase(*it3) == 1 ); + VERIFY( s1.size() == 7 ); + it3 = s1.find("belonging (no longer mix)"); + VERIFY( it3 == s1.end() ); + + VERIFY( !s1.erase("abra") ); + VERIFY( s1.size() == 7 ); + + VERIFY( !s1.erase("eeilo") ); + VERIFY( s1.size() == 7 ); + + VERIFY( s1.erase("because to why") == 1 ); + VERIFY( s1.size() == 6 ); + iterator it4 = s1.find("because to why"); + VERIFY( it4 == s1.end() ); + + iterator it5 = s1.find("umbra/penumbra"); + iterator it6 = s1.find("one line behind"); + VERIFY( it5 != s1.end() ); + VERIFY( it6 != s1.end() ); + + VERIFY( s1.find("the stockholm syndrome") != s1.end() ); + VERIFY( s1.find("a cereous night") != s1.end() ); + VERIFY( s1.find("the way you are when") != s1.end() ); + VERIFY( s1.find("a cereous night") != s1.end() ); + + VERIFY( s1.erase(*it5) == 1 ); + VERIFY( s1.size() == 5 ); + it5 = s1.find("umbra/penumbra"); + VERIFY( it5 == s1.end() ); + + VERIFY( s1.erase(*it6) == 1 ); + VERIFY( s1.size() == 4 ); + it6 = s1.find("one line behind"); + VERIFY( it6 == s1.end() ); + + iterator it7 = s1.begin(); + iterator it8 = it7; + ++it8; + iterator it9 = it8; + ++it9; + + VERIFY( s1.erase(*it8) == 1 ); + VERIFY( s1.size() == 3 ); + VERIFY( ++it7 == it9 ); + + iterator it10 = it9; + ++it10; + iterator it11 = it10; + + VERIFY( s1.erase(*it9) == 1 ); + VERIFY( s1.size() == 2 ); + VERIFY( ++it10 == s1.end() ); + + VERIFY( s1.erase(s1.begin()) != s1.end() ); + VERIFY( s1.size() == 1 ); + VERIFY( s1.begin() == it11 ); + + VERIFY( s1.erase(*s1.begin()) == 1 ); + VERIFY( s1.size() == 0 ); + VERIFY( s1.begin() == s1.end() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/erase/24061-set.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/24061-set.cc new file mode 100644 index 000000000..b4cdde62d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/24061-set.cc @@ -0,0 +1,104 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_set<std::string> Set; + typedef Set::iterator iterator; + typedef Set::const_iterator const_iterator; + + Set s1; + + s1.insert("all the love in the world"); + s1.insert("you know what you are?"); + s1.insert("the collector"); + s1.insert("the hand that feeds"); + s1.insert("love is not enough"); + s1.insert("every day is exactly the same"); + s1.insert("with teeth"); + s1.insert("only"); + s1.insert("getting smaller"); + s1.insert("sunspots"); + VERIFY( s1.size() == 10 ); + + iterator it1 = s1.begin(); + ++it1; + iterator it2 = it1; + ++it2; + iterator it3 = s1.erase(it1); + VERIFY( s1.size() == 9 ); + VERIFY( it3 == it2 ); + VERIFY( *it3 == *it2 ); + + iterator it4 = s1.begin(); + ++it4; + ++it4; + ++it4; + iterator it5 = it4; + ++it5; + ++it5; + iterator it6 = s1.erase(it4, it5); + VERIFY( s1.size() == 7 ); + VERIFY( it6 == it5 ); + VERIFY( *it6 == *it5 ); + + const_iterator it7 = s1.begin(); + ++it7; + ++it7; + ++it7; + const_iterator it8 = it7; + ++it8; + const_iterator it9 = s1.erase(it7); + VERIFY( s1.size() == 6 ); + VERIFY( it9 == it8 ); + VERIFY( *it9 == *it8 ); + + const_iterator it10 = s1.begin(); + ++it10; + const_iterator it11 = it10; + ++it11; + ++it11; + ++it11; + ++it11; + const_iterator it12 = s1.erase(it10, it11); + VERIFY( s1.size() == 2 ); + VERIFY( it12 == it11 ); + VERIFY( *it12 == *it11 ); + VERIFY( ++it12 == s1.end() ); + + iterator it13 = s1.erase(s1.begin(), s1.end()); + VERIFY( s1.size() == 0 ); + VERIFY( it13 == s1.end() ); + VERIFY( it13 == s1.begin() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/erase/51142.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/51142.cc new file mode 100644 index 000000000..148646042 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/erase/51142.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2011 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/>. +// + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <unordered_set> + +struct X +{ + template<typename T> + X(T&) {} +}; + +bool operator==(const X&, const X&) { return false; } + +// LWG 2059. +void erasor(std::unordered_set<X>& s, X x) +{ + std::unordered_set<X>::iterator it = s.find(x); + if (it != s.end()) + s.erase(it); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/26132.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/26132.cc new file mode 100644 index 000000000..afa1ddd5d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/26132.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-08-13 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <testsuite_hooks.h> + +// libstdc++/26132 +void test01() +{ + bool test __attribute__((unused)) = true; + + for (float lf = 1.0; lf < 101.0; lf *= 10.0) + for (int size = 1; size <= 6561; size *= 3) + { + std::unordered_set<int> us1; + typedef std::unordered_set<int>::size_type size_type; + + us1.max_load_factor(10.0); + + for (int i = 0; i < size; ++i) + us1.insert(i); + + us1.max_load_factor(lf); + + for (int i = 1; i <= 6561; i *= 81) + { + const size_type n = size * 81 / i; + us1.rehash(n); + VERIFY( us1.bucket_count() > us1.size() / us1.max_load_factor() ); + VERIFY( us1.bucket_count() >= n ); + } + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/dr1189.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/dr1189.cc new file mode 100644 index 000000000..e7047dbdd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/dr1189.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++0x" } +// 2010-03-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <testsuite_hooks.h> + +// DR 1189. Awkward interface for changing the number of buckets +// in an unordered associative container +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unordered_set<int> s1; + s1.reserve(10); + VERIFY( s1.bucket_count() >= 10 ); + + s1.reserve(100); + VERIFY( s1.bucket_count() >= 100 ); + + std::unordered_set<int> s2(100); + VERIFY( s2.bucket_count() >= 100 ); + + s2.reserve(1000); + VERIFY( s2.bucket_count() >= 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/init-list.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/init-list.cc new file mode 100644 index 000000000..adcd8a440 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/init-list.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <unordered_set> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + unordered_set<int> m({ 1, 5, 37 }); + VERIFY(m.size() == 3); + VERIFY(m.count(1) == 1); + VERIFY(m.count(5) == 1); + VERIFY(m.count(37) == 1); + VERIFY(m.count(42) == 0); + + m = { 28, 37, 102 }; + VERIFY(m.size() == 3); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 1); + VERIFY(m.count(102) == 1); + VERIFY(m.count(1) == 0); + + m.insert({ 42 }); + VERIFY(m.size() == 4); + VERIFY(m.count(28) == 1); + VERIFY(m.count(37) == 1); + VERIFY(m.count(102) == 1); + VERIFY(m.count(42) == 1); + VERIFY(m.count(1) == 0); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/insert/24061-set.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/24061-set.cc new file mode 100644 index 000000000..54add3512 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/24061-set.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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 <unordered_set> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/24061 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_set<std::string> Set; + typedef Set::iterator iterator; + typedef Set::const_iterator const_iterator; + + Set s1; + + iterator it1 = s1.insert(s1.begin(), "all the love in the world"); + VERIFY( s1.size() == 1 ); + VERIFY( *it1 == "all the love in the world" ); + + const_iterator cit1(it1); + const_iterator cit2 = s1.insert(cit1, "you know what you are?"); + VERIFY( s1.size() == 2 ); + VERIFY( cit2 != cit1 ); + VERIFY( *cit2 == "you know what you are?" ); + + iterator it2 = s1.insert(it1, "all the love in the world"); + VERIFY( s1.size() == 2 ); + VERIFY( it2 == it1 ); + VERIFY( *it2 == "all the love in the world" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_range.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_range.cc new file mode 100644 index 000000000..86bd326bd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_range.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// range insert + +#include <string> +#include <iterator> +#include <algorithm> +#include <unordered_set> +#include <testsuite_hooks.h> + +bool test __attribute__((unused)) = true; + +void test01() +{ + typedef std::unordered_set<std::string> Set; + Set s; + VERIFY(s.empty()); + + const int N = 10; + const std::string A[N] = { "red", "green", "blue", "violet", "cyan", + "magenta", "yellow", "orange", "pink", "gray" }; + + s.insert(A+0, A+N); + VERIFY(s.size() == static_cast<unsigned int>(N)); + VERIFY(std::distance(s.begin(), s.end()) == N); + + for (int i = 0; i < N; ++i) { + std::string str = A[i]; + Set::iterator it = std::find(s.begin(), s.end(), str); + VERIFY(it != s.end()); + } +} + +void test02() +{ + typedef std::unordered_set<int> Set; + Set s; + VERIFY(s.empty()); + + const int N = 8; + const int A[N] = { 3, 7, 4, 8, 2, 4, 6, 7 }; + + s.insert(A+0, A+N); + VERIFY(s.size() == 6); + VERIFY(std::distance(s.begin(), s.end()) == 6); + + VERIFY(std::count(s.begin(), s.end(), 2) == 1); + VERIFY(std::count(s.begin(), s.end(), 3) == 1); + VERIFY(std::count(s.begin(), s.end(), 4) == 1); + VERIFY(std::count(s.begin(), s.end(), 6) == 1); + VERIFY(std::count(s.begin(), s.end(), 7) == 1); + VERIFY(std::count(s.begin(), s.end(), 8) == 1); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single.cc new file mode 100644 index 000000000..d1288ce42 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single.cc @@ -0,0 +1,65 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <string> +#include <iterator> +#include <unordered_set> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_set<std::string> Set; + Set s; + VERIFY(s.empty()); + + std::pair<Set::iterator, bool> p = s.insert("abcde"); + VERIFY(p.second); + VERIFY(s.size() == 1); + VERIFY(std::distance(s.begin(), s.end()) == 1); + VERIFY(p.first == s.begin()); + VERIFY(*p.first == "abcde"); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_set<std::string> Set; + Set s; + VERIFY(s.empty()); + + std::pair<Set::iterator, bool> p1 = s.insert("abcde"); + std::pair<Set::iterator, bool> p2 = s.insert("abcde"); + VERIFY(p1.second); + VERIFY(!p2.second); + VERIFY(s.size() == 1); + VERIFY(p1.first == p2.first); + VERIFY(*p1.first == "abcde"); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single_move.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single_move.cc new file mode 100644 index 000000000..0b9ad173b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single_move.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// Single-element insert + +#include <iterator> +#include <unordered_set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + std::pair<Set::iterator, bool> p = s.insert(rvalstruct(1)); + VERIFY( p.second ); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p.first == s.begin() ); + VERIFY( (*p.first).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::unordered_set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + std::pair<Set::iterator, bool> p1 = s.insert(rvalstruct(2)); + std::pair<Set::iterator, bool> p2 = s.insert(rvalstruct(2)); + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( s.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (*p1.first).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/operators/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/operators/1.cc new file mode 100644 index 000000000..63e726d04 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/operators/1.cc @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-03-25 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <unordered_set> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::unordered_set<int> us1, us2; + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(1); + us2.insert(1); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(2); + us2.insert(2); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(1); + us2.insert(1); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(3); + VERIFY( us1 != us2 ); + VERIFY( !(us1 == us2) ); + + us2.insert(3); + VERIFY( (us1 == us2) ); + VERIFY( !(us1 != us2) ); + + us2.clear(); + VERIFY( us1 != us2 ); + VERIFY( !(us1 == us2) ); + + us1.clear(); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(1); + us2.insert(2); + VERIFY( us1 != us2 ); + VERIFY( !(us1 == us2) ); + + us1.insert(2); + us2.insert(1); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(3); + us2.insert(4); + VERIFY( us1 != us2 ); + VERIFY( !(us1 == us2) ); + + us1.insert(4); + VERIFY( us1 != us2 ); + VERIFY( !(us1 == us2) ); + + us2.insert(3); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(1); + us2.insert(1); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + us1.insert(4); + us2.insert(4); + VERIFY( us1 == us2 ); + VERIFY( !(us1 != us2) ); + + const std::unordered_set<int> cus1(us1), cus2(us2); + VERIFY( cus1 == cus2 ); + VERIFY( !(cus1 != cus2) ); + VERIFY( cus1 == us2 ); + VERIFY( !(us1 != cus2) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/operators/52309.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/operators/52309.cc new file mode 100644 index 000000000..5b16f0b3c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/operators/52309.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2012 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 <unordered_set> + +// libstdc++/52309 +struct value {}; +struct hash { std::size_t operator()(const value&) const; }; +bool operator==(value const&, value const&); +std::unordered_set<value, hash> set; +bool z = (set == set); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc new file mode 100644 index 000000000..2bb738afd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <unordered_set> + +void +test01() +{ + std::unordered_set<int> us{1, 2, 3}; + std::begin(us); + std::end(us); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/citerators.cc new file mode 100644 index 000000000..ce7f79fd6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <unordered_set> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_set<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/cliterators.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/cliterators.cc new file mode 100644 index 000000000..8abef8c1c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/cliterators.cc @@ -0,0 +1,32 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-06-11 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008, 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 <unordered_set> +#include <testsuite_containers.h> + +int main() +{ + typedef std::unordered_set<int> test_type; + typedef typename test_type::value_type value_type; + value_type v(1); + __gnu_test::forward_members_unordered<test_type> test(v); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_container.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_container.cc new file mode 100644 index 000000000..f2405fa4b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_container.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <debug/unordered_set> + +using namespace __gnu_debug; + +template class unordered_set<int>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_mode.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_mode.cc new file mode 100644 index 000000000..206b70437 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_mode.cc @@ -0,0 +1,30 @@ +// NB: This issue affected only debug-mode. + +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 2008, 2009, 2010 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 <unordered_set> + +//PR libstdc++/35922 +int main() +{ + std::unordered_set<int> s; +} + diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/basic.cc new file mode 100644 index 000000000..6d0e3f52b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/basic.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_set> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_set<value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..0841cf013 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/generation_prohibited.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_set<value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..ab1d74d03 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/exception/propagation_consistent.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <unordered_set> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::hash<value_type> hash_type; + typedef std::equal_to<value_type> pred_type; + typedef std::unordered_set<value_type, hash_type, pred_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..10d0bf566 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/1.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_set> + +template class std::unordered_set<int>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..e22760460 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/2.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::NonDefaultConstructible inst_type; +typedef __gnu_test::NonDefaultConstructible_hash hash_type; +template class std::unordered_set<inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..7d84ffd7f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/3.cc @@ -0,0 +1,24 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2007, 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 <unordered_set> + +using namespace std; +template class unordered_set<int, hash<int>, equal_to<int>, allocator<char>>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..3f619b71c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/4.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <unordered_set> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +typedef __gnu_test::OverloadedAddress inst_type; +typedef __gnu_test::OverloadedAddress_hash hash_type; + +// libstdc++/41792 +template class std::unordered_set<inst_type, hash_type>; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/typedefs.cc new file mode 100644 index 000000000..86983e5a6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <unordered_set> + +// Check container for required typedefs. +__gnu_test::types<std::unordered_set<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/vector/14340.cc b/libstdc++-v3/testsuite/23_containers/vector/14340.cc new file mode 100644 index 000000000..0d4e45df9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/14340.cc @@ -0,0 +1,34 @@ +// -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <testsuite_hooks.h> +#include <vector> + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/14340 +int main() +{ + typedef std::vector<int> container; + __gnu_test::conversion<container>::iterator_to_const_iterator(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/15523.cc b/libstdc++-v3/testsuite/23_containers/vector/15523.cc new file mode 100644 index 000000000..c5f489483 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/15523.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2009, 2010 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/>. + +// NB: This issue affected only debug-mode. + +#include <vector> + +// libstdc++/15523 +void test01() +{ + using namespace std; + + vector<vector<int>::const_iterator> x(2); + + vector<int>::iterator i2, i3; + vector<int>::const_iterator ci1(i2); + + i2 = i3; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/18604.cc b/libstdc++-v3/testsuite/23_containers/vector/18604.cc new file mode 100644 index 000000000..6ebd30833 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/18604.cc @@ -0,0 +1,42 @@ +// 2005-05-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-do compile } + +// libstdc++/18604 +struct less; +struct allocator; +struct pair; +struct binary_function; +struct iterator; +struct iterator_traits; +struct bidirectional_iterator_tag; +struct forward_iterator_tag; +struct input_iterator_tag; +struct random_access_iterator_tag; +struct ios_base; +struct basic_string; +struct basic_istream; +struct basic_ostream; +struct char_traits; + +#include <vector> diff --git a/libstdc++-v3/testsuite/23_containers/vector/26412-1.cc b/libstdc++-v3/testsuite/23_containers/vector/26412-1.cc new file mode 100644 index 000000000..dd8c1bade --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/26412-1.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// -*- C++ -*- + +// Copyright (C) 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 <vector> + +// libstdc++26412 +namespace debug +{ + int i; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/26412-2.cc b/libstdc++-v3/testsuite/23_containers/vector/26412-2.cc new file mode 100644 index 000000000..df4350dd5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/26412-2.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// -*- C++ -*- + +// Copyright (C) 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/>. + + +#define debug 0 + +#include <debug/vector> + +// libstdc++26412 diff --git a/libstdc++-v3/testsuite/23_containers/vector/40192.cc b/libstdc++-v3/testsuite/23_containers/vector/40192.cc new file mode 100644 index 000000000..eff88d422 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/40192.cc @@ -0,0 +1,28 @@ +// 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/>. + +// { dg-do compile } + +// libstdc++/40192 + +#include <vector> + +void test01() +{ + typedef float float4[4]; + std::vector<float4> vals; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/1.cc new file mode 100644 index 000000000..8728985e8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/1.cc @@ -0,0 +1,36 @@ +// 2002-03-05 Stephen M. Webb <stephen.webb@bregmasoft.com> + +// Copyright (C) 2002, 2003, 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.5 class vector<bool> + +#include <vector> +#include <testsuite_hooks.h> + +void test01() +{ + std::vector<bool>::iterator i; + if (false) + ++i; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/21244.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/21244.cc new file mode 100644 index 000000000..f8baba1be --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/21244.cc @@ -0,0 +1,35 @@ +// 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 <vector> + +// { dg-do compile } + +class Foo +{ +}; + +template<class T> Foo operator/(const Foo& arg1, T arg2) +{ + return Foo(); +} + +// libstdc++/21244 +void foo() +{ + std::vector<bool> bar(1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/23632.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/23632.cc new file mode 100644 index 000000000..9b5023f98 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/23632.cc @@ -0,0 +1,39 @@ +// 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/>. + +// { dg-do compile } + +#include <vector> + +// libstdc++/23632 +void test01() +{ + std::vector<bool> v(100); + const std::vector<bool>::iterator fu = v.begin(); + if (!fu[0]) + fu[0] = true; + + const std::vector<bool>::const_iterator cfu = v.begin(); + if (cfu[0]) + ; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/6886.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/6886.cc new file mode 100644 index 000000000..c3a2995ae --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/6886.cc @@ -0,0 +1,53 @@ +// 2002-03-05 Stephen M. Webb <stephen.webb@bregmasoft.com> + +// Copyright (C) 2002, 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.5 class vector<bool> + +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/6886 +void test02() +{ + bool test __attribute__((unused)) = true; + typedef std::vector<bool> bvec; + int i, num = 0; + bvec v; + + v.resize(66); + + for (i = 0 ; i < 66 ; ++i) + v[i] = 0; + + v[1] = 1; + v[33] = 1; + v[49] = 1; + v[65] = 1; + + for (bvec::iterator j = v.begin() ; j != v.end() ; j++) + if (bool(*j)) ++num; + + VERIFY( num == 4 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc new file mode 100644 index 000000000..c38ac7115 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc @@ -0,0 +1,137 @@ +// 2006-08-05 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.5 vector<bool> resize + +#include <vector> +#include <testsuite_hooks.h> + +const bool A1[] = {0}; +const bool A2[] = {0, 0, 0}; +const bool A3[] = {0, 0}; +const bool A4[] = {0, 0, 1, 1, 1, 1, 1}; +const bool A5[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +const bool A6[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1}; +const bool A7[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; +const bool A8[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; +const bool A9[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +const bool A10[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1}; +const bool A11[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}; + +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); +const unsigned N6 = sizeof(A6) / sizeof(bool); +const unsigned N7 = sizeof(A7) / sizeof(bool); +const unsigned N8 = sizeof(A8) / sizeof(bool); +const unsigned N9 = sizeof(A9) / sizeof(bool); +const unsigned N10 = sizeof(A10) / sizeof(bool); +const unsigned N11 = sizeof(A11) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<bool> vec_type; + + vec_type v; + + v.resize(1); + VERIFY( v.size() == 1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + v.resize(3); + VERIFY( v.size() == 3 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + v.resize(2); + VERIFY( v.size() == 2 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + v.resize(7, true); + VERIFY( v.size() == 7 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + v.resize(18, false); + VERIFY( v.size() == 18 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + v.resize(40, true); + VERIFY( v.size() == 40 ); + VERIFY( std::equal(v.begin(), v.end(), A6) ); + + v.resize(80, false); + VERIFY( v.size() == 80 ); + VERIFY( std::equal(v.begin(), v.end(), A7) ); + + v.resize(90, true); + VERIFY( v.size() == 90 ); + VERIFY( std::equal(v.begin(), v.end(), A8) ); + + v.resize(100, false); + VERIFY( v.size() == 100 ); + VERIFY( std::equal(v.begin(), v.end(), A9) ); + + v.resize(200, true); + VERIFY( v.size() == 200 ); + VERIFY( std::equal(v.begin(), v.end(), A10) ); + + v.resize(13, true); + VERIFY( v.size() == 13 ); + VERIFY( std::equal(v.begin(), v.end(), A11) ); + + v.resize(13, false); + VERIFY( v.size() == 13 ); + VERIFY( std::equal(v.begin(), v.end(), A11) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/29134.cc new file mode 100644 index 000000000..f6d0e15ed --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/29134.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2006, 2007, 2009, 2010 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.5 class vector<bool> [lib.vector.bool] + +#include <vector> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + using std::vector; + using std::numeric_limits; + +#ifdef _GLIBCXX_DEBUG + using std::_GLIBCXX_STD_C::_S_word_bit; +#elif defined(_GLIBCXX_PROFILE) + using std::_GLIBCXX_STD_C::_S_word_bit; +#else + using std::_S_word_bit; +#endif + + // Actually, vector<bool> is special, see libstdc++/31370. + vector<bool> vb; + typedef vector<bool>::difference_type difference_type; + typedef vector<bool>::size_type size_type; + VERIFY( vb.max_size() + == size_type(numeric_limits<difference_type>::max() + - int(_S_word_bit) + 1) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/clear_allocator.cc new file mode 100644 index 000000000..934f1be33 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/clear_allocator.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004, 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 <vector> +#include <ext/new_allocator.h> + +using namespace std; +using __gnu_cxx::new_allocator; + +template<typename T> + class clear_alloc : public new_allocator<T> + { + public: + + template <typename T1> + struct rebind + { typedef clear_alloc<T1> other; }; + + virtual void clear() throw() + { } + + clear_alloc() throw() + { } + + clear_alloc(clear_alloc const&) throw() : new_allocator<T>() + { } + + template<typename T1> + clear_alloc(clear_alloc<T1> const&) throw() + { } + + virtual ~clear_alloc() throw() + { this->clear(); } + + T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0) + { + this->clear(); + return new_allocator<T>::allocate(n, hint); + } + + void deallocate(T *ptr, typename new_allocator<T>::size_type n) + { + this->clear(); + new_allocator<T>::deallocate(ptr, n); + } + }; + +template<typename Container> + void Check_Container() + { + Container* pic = new Container; + int x = 230; + + while (x--) + { + pic->push_back(x); + } + + pic->get_allocator(); + + // The following has led to infinite recursions or cores. + pic->clear(); + + delete pic; + } + + +int main() +{ + Check_Container<std::vector<bool, clear_alloc<bool> > >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/1.cc new file mode 100644 index 000000000..ce377b466 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/1.cc @@ -0,0 +1,178 @@ +// 2006-08-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.5 vector<bool> copy construct + +#include <vector> +#include <testsuite_hooks.h> + +const bool A1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 1, 1}; +const bool A2[] = {1, 0, 1, 1, 1, 1, 1}; +const bool A3[] = {1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1}; +const bool A5[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1}; +const bool A6[] = {1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A7[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 0}; +const bool A8[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; +const bool A9[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; + +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); +const unsigned N6 = sizeof(A6) / sizeof(bool); +const unsigned N7 = sizeof(A7) / sizeof(bool); +const unsigned N8 = sizeof(A8) / sizeof(bool); +const unsigned N9 = sizeof(A9) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<bool> vec_type; + + const vec_type v1_ref(A1, A1 + N1); + vec_type v1(v1_ref); + VERIFY( v1.size() == v1_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v1_ref.begin()) ); + + const vec_type v2_ref(A2, A2 + N2); + vec_type v2(v2_ref); + VERIFY( v2.size() == v2_ref.size() ); + VERIFY( std::equal(v2.begin(), v2.end(), v2_ref.begin()) ); + + const vec_type v3_ref(A3, A3 + N3); + vec_type v3(v3_ref); + VERIFY( v3.size() == v3_ref.size() ); + VERIFY( std::equal(v3.begin(), v3.end(), v3_ref.begin()) ); + + const vec_type v4_ref(A4, A4 + N4); + vec_type v4(v4_ref); + VERIFY( v4.size() == v4_ref.size() ); + VERIFY( std::equal(v4.begin(), v4.end(), v4_ref.begin()) ); + + const vec_type v5_ref(A5, A5 + N5); + vec_type v5(v5_ref); + VERIFY( v5.size() == v5_ref.size() ); + VERIFY( std::equal(v5.begin(), v5.end(), v5_ref.begin()) ); + + const vec_type v6_ref(A6, A6 + N6); + vec_type v6(v6_ref); + VERIFY( v6.size() == v6_ref.size() ); + VERIFY( std::equal(v6.begin(), v6.end(), v6_ref.begin()) ); + + const vec_type v7_ref(A7, A7 + N7); + vec_type v7(v7_ref); + VERIFY( v7.size() == v7_ref.size() ); + VERIFY( std::equal(v7.begin(), v7.end(), v7_ref.begin()) ); + + const vec_type v8_ref(A8, A8 + N8); + vec_type v8(v8_ref); + VERIFY( v8.size() == v8_ref.size() ); + VERIFY( std::equal(v8.begin(), v8.end(), v8_ref.begin()) ); + + const vec_type v9_ref(A9, A9 + N9); + vec_type v9(v9_ref); + VERIFY( v9.size() == v9_ref.size() ); + VERIFY( std::equal(v9.begin(), v9.end(), v9_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/2.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/2.cc new file mode 100644 index 000000000..34ac3a0fd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/2.cc @@ -0,0 +1,180 @@ +// 2006-08-09 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.5 vector<bool> assignment operator + +#include <vector> +#include <testsuite_hooks.h> + +const bool A1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 1, 1}; +const bool A2[] = {1, 0, 1, 1, 1, 1, 1}; +const bool A3[] = {1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1}; +const bool A5[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1}; +const bool A6[] = {1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A7[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 0}; +const bool A8[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; +const bool A9[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; + +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); +const unsigned N6 = sizeof(A6) / sizeof(bool); +const unsigned N7 = sizeof(A7) / sizeof(bool); +const unsigned N8 = sizeof(A8) / sizeof(bool); +const unsigned N9 = sizeof(A9) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<bool> vec_type; + + vec_type v1; + + const vec_type v1_ref(A1, A1 + N1); + v1 = v1_ref; + VERIFY( v1.size() == v1_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v1_ref.begin()) ); + + const vec_type v2_ref(A2, A2 + N2); + v1 = v2_ref; + VERIFY( v1.size() == v2_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v2_ref.begin()) ); + + const vec_type v3_ref(A3, A3 + N3); + v1 = v3_ref; + VERIFY( v1.size() == v3_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v3_ref.begin()) ); + + const vec_type v4_ref(A4, A4 + N4); + v1 = v4_ref; + VERIFY( v1.size() == v4_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v4_ref.begin()) ); + + const vec_type v5_ref(A5, A5 + N5); + v1 = v5_ref; + VERIFY( v1.size() == v5_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v5_ref.begin()) ); + + const vec_type v6_ref(A6, A6 + N6); + v1 = v6_ref; + VERIFY( v1.size() == v6_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v6_ref.begin()) ); + + const vec_type v7_ref(A7, A7 + N7); + v1 = v7_ref; + VERIFY( v1.size() == v7_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v7_ref.begin()) ); + + const vec_type v8_ref(A8, A8 + N8); + v1 = v8_ref; + VERIFY( v1.size() == v8_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v8_ref.begin()) ); + + const vec_type v9_ref(A9, A9 + N9); + v1 = v9_ref; + VERIFY( v1.size() == v9_ref.size() ); + VERIFY( std::equal(v1.begin(), v1.end(), v9_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/hash/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/hash/1.cc new file mode 100644 index 000000000..85e91e98e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/hash/1.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 <vector> + +void test01() +{ + std::vector<bool> b0; + std::hash<std::vector<bool>> h0; + h0(b0); + + std::vector<bool> b1(10); + std::hash<std::vector<bool>> h1; + h1(b1); + + std::vector<bool> b2(100); + std::hash<std::vector<bool>> h2; + h2(b2); + + std::vector<bool> b3(1000); + std::hash<std::vector<bool>> h3; + h3(b3); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/erase/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/erase/1.cc new file mode 100644 index 000000000..2a21fcf9e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/erase/1.cc @@ -0,0 +1,136 @@ +// 2005-12-23 Paolo Carlini <pcarlini@suse.de> + +// 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.5 vector<bool> modifiers + +#include <vector> +#include <testsuite_hooks.h> + +const bool A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; +const bool A1[] = {0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; +const bool A2[] = {0, 0, 1, 0, 0, 1, 0, 1, 0, 1}; +const bool A3[] = {0, 0, 1, 0, 0, 1}; +const bool A4[] = {0, 0, 1}; +const bool A5[] = {0, 0}; + +const unsigned N = sizeof(A) / sizeof(bool); +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<bool> vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v(A, A + N); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<std::vector<bool> > vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v, v1, v2, v3, v4, v5; + for (unsigned i = 0; i < N; ++i) + v.push_back(std::vector<bool>(1, A[i])); + for (unsigned i = 0; i < N1; ++i) + v1.push_back(std::vector<bool>(1, A1[i])); + for (unsigned i = 0; i < N2; ++i) + v2.push_back(std::vector<bool>(1, A2[i])); + for (unsigned i = 0; i < N3; ++i) + v3.push_back(std::vector<bool>(1, A3[i])); + for (unsigned i = 0; i < N4; ++i) + v4.push_back(std::vector<bool>(1, A4[i])); + for (unsigned i = 0; i < N5; ++i) + v5.push_back(std::vector<bool>(1, A5[i])); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), v1.begin()) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), v2.begin()) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), v3.begin()) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), v4.begin()) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), v5.begin()) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc new file mode 100644 index 000000000..06fe0be97 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc @@ -0,0 +1,171 @@ +// 2006-08-05 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 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.5 vector<bool> insert + +#include <vector> +#include <testsuite_hooks.h> + +const bool A1[] = {1, 1, 1, 1, 1, 1, 1}; +const bool A2[] = {1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A3[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1}; +const bool A4[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1}; +const bool A5[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A6[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1}; +const bool A7[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 0}; +const bool A8[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; +const bool A9[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; + +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); +const unsigned N6 = sizeof(A6) / sizeof(bool); +const unsigned N7 = sizeof(A7) / sizeof(bool); +const unsigned N8 = sizeof(A8) / sizeof(bool); +const unsigned N9 = sizeof(A9) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<bool> vec_type; + + vec_type v; + + v.insert(v.begin(), 7, true); + VERIFY( v.size() == 7 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + v.insert(v.begin() + 5, 10, false); + VERIFY( v.size() == 17 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + v.insert(v.begin(), 20, false); + VERIFY( v.size() == 37 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + v.insert(v.begin(), 40, true); + VERIFY( v.size() == 77 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + v.insert(v.begin() + 18, 80, false); + VERIFY( v.size() == 157 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + v.insert(v.begin() + 54, 80, true); + VERIFY( v.size() == 237 ); + VERIFY( std::equal(v.begin(), v.end(), A6) ); + + v.insert(v.end(), 1, false); + VERIFY( v.size() == 238 ); + VERIFY( std::equal(v.begin(), v.end(), A7) ); + + v.insert(v.begin(), 1, false); + VERIFY( v.size() == 239 ); + VERIFY( std::equal(v.begin(), v.end(), A8) ); + + v.insert(v.begin(), 180, true); + VERIFY( v.size() == 419 ); + VERIFY( std::equal(v.begin(), v.end(), A9) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/31370.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/31370.cc new file mode 100644 index 000000000..9f5643ef9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/31370.cc @@ -0,0 +1,199 @@ +// Copyright (C) 2007, 2009, 2010 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.5 class vector<bool> [lib.vector.bool] + +// { dg-do run { xfail *-*-darwin8.[0-4].* } } + +#include <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +#ifdef _GLIBCXX_DEBUG + using std::_GLIBCXX_STD_C::_S_word_bit; +#elif defined(_GLIBCXX_PROFILE) + using std::_GLIBCXX_STD_C::_S_word_bit; +#else + using std::_S_word_bit; +#endif + +inline void +check_cap_ge_size(const std::vector<bool>& x) +{ + if (x.capacity() < x.size()) + throw std::logic_error(""); +} + +inline void +check_cap_eq_maxsize(const std::vector<bool>& x) +{ + if (x.capacity() != x.max_size()) + throw std::logic_error(""); +} + +// libstdc++/31370 +void test01() +{ + bool test __attribute__((unused)) = true; + int myexit = 0; + + try + { + std::vector<bool> x; + x.reserve(x.max_size()); + check_cap_eq_maxsize(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + // When doubling is too big, but smaller is sufficient, the resize + // should do smaller and be happy. It certainly shouldn't throw + // other exceptions or crash. + try + { + std::vector<bool> x; + x.resize(x.max_size() / 2 + 1, false); + for(int i = 0; i < _S_word_bit; ++i) + x.push_back(false); + check_cap_ge_size(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + try + { + std::vector<bool> x; + x.resize(x.max_size() / 2 + 1, false); + x.insert(x.end(), _S_word_bit, false); + check_cap_ge_size(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + try + { + std::vector<bool> x; + x.resize(x.max_size() / 2 + 1, false); + std::vector<bool> y(_S_word_bit, false); + x.insert(x.end(), y.begin(), y.end()); + check_cap_ge_size(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + // These tests are currently only relevant to bool: don't get burned + // by the attempt to round up when near the max size. + try + { + std::vector<bool> x; + x.resize(x.max_size() - _S_word_bit, false); + for(int i = 0; i < _S_word_bit; ++i) + x.push_back(false); + check_cap_ge_size(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + try + { + std::vector<bool> x; + x.resize(x.max_size() - _S_word_bit, false); + x.insert(x.end(), _S_word_bit, false); + check_cap_ge_size(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + try + { + std::vector<bool> x; + x.resize(x.max_size() - _S_word_bit, false); + std::vector<bool> y(_S_word_bit, false); + x.insert(x.end(), y.begin(), y.end()); + check_cap_ge_size(x); + } + catch(std::bad_alloc&) + { } + catch(std::exception&) + { ++myexit; } + + // Attempts to put in more than max_size() items should result in a + // length error. + try + { + std::vector<bool> x; + x.resize(x.max_size() - _S_word_bit, false); + for(int i = 0; i < _S_word_bit + 1; ++i) + x.push_back(false); + ++myexit; + } + catch(std::bad_alloc) + { } + catch(std::length_error) + { } + catch(std::exception) + { ++myexit; } + + try + { + std::vector<bool> x; + x.resize(x.max_size() - _S_word_bit, false); + x.insert(x.end(), _S_word_bit + 1, false); + ++myexit; + } + catch(std::bad_alloc) + { } + catch(std::length_error) + { } + catch(std::exception) + { ++myexit; } + + try + { + std::vector<bool> x; + x.resize(x.max_size() - _S_word_bit, false); + std::vector<bool> y(_S_word_bit + 1, false); + x.insert(x.end(), y.begin(), y.end()); + ++myexit; + } + catch(std::bad_alloc) + { } + catch(std::length_error) + { } + catch(std::exception) + { ++myexit; } + + VERIFY( !myexit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/1.cc new file mode 100644 index 000000000..31152845b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/1.cc @@ -0,0 +1,145 @@ +// 2005-12-23 Paolo Carlini <pcarlini@suse.de> + +// 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.5 vector<bool>::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<bool> my_alloc; + typedef vector<bool, my_alloc> my_vector; + + 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); + + vector<bool> vec01_ref; + for (size_t i = 0; i < N1; ++i) + vec01_ref.push_back(bool(title01[i] > 96 ? 1 : 0)); + vector<bool> vec02_ref; + for (size_t i = 0; i < N2; ++i) + vec02_ref.push_back(bool(title02[i] > 96 ? 1 : 0)); + vector<bool> vec03_ref; + for (size_t i = 0; i < N3; ++i) + vec03_ref.push_back(bool(title03[i] > 96 ? 1 : 0)); + vector<bool> vec04_ref; + for (size_t i = 0; i < N4; ++i) + vec04_ref.push_back(bool(title04[i] > 96 ? 1 : 0)); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1); + + my_vector vec01(alloc01); + size01 = vec01.size(); + my_vector vec02(alloc01); + size02 = vec02.size(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + + my_vector vec03(alloc01); + size01 = vec03.size(); + my_vector vec04(vec02_ref.begin(), vec02_ref.end(), alloc01); + size02 = vec04.size(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), vec02_ref.begin()) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + + my_vector vec05(vec01_ref.begin(), vec01_ref.end(), alloc01); + size01 = vec05.size(); + my_vector vec06(vec02_ref.begin(), vec02_ref.end(), alloc01); + size02 = vec06.size(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), vec02_ref.begin()) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), vec01_ref.begin()) ); + + my_vector vec07(vec01_ref.begin(), vec01_ref.end(), alloc01); + size01 = vec07.size(); + my_vector vec08(vec03_ref.begin(), vec03_ref.end(), alloc01); + size02 = vec08.size(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), vec03_ref.begin()) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), vec01_ref.begin()) ); + + my_vector vec09(vec03_ref.begin(), vec03_ref.end(), alloc01); + size01 = vec09.size(); + my_vector vec10(vec04_ref.begin(), vec04_ref.end(), alloc01); + size02 = vec10.size(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), vec04_ref.begin()) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), vec03_ref.begin()) ); + + my_vector vec11(vec04_ref.begin(), vec04_ref.end(), alloc01); + size01 = vec11.size(); + my_vector vec12(vec01_ref.begin(), vec01_ref.end(), alloc01); + size02 = vec12.size(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), vec01_ref.begin()) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), vec04_ref.begin()) ); + + my_vector vec13(vec03_ref.begin(), vec03_ref.end(), alloc01); + size01 = vec13.size(); + my_vector vec14(vec03_ref.begin(), vec03_ref.end(), alloc01); + size02 = vec14.size(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), vec03_ref.begin()) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), vec03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/2.cc new file mode 100644 index 000000000..f63b6a257 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/2.cc @@ -0,0 +1,174 @@ +// 2005-12-23 Paolo Carlini <pcarlini@suse.de> + +// 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.5 vector<bool>::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<bool> my_alloc; + typedef vector<bool, my_alloc> my_vector; + + 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); + + vector<bool> vec01_ref; + for (size_t i = 0; i < N1; ++i) + vec01_ref.push_back(bool(title01[i] > 96 ? 1 : 0)); + vector<bool> vec02_ref; + for (size_t i = 0; i < N2; ++i) + vec02_ref.push_back(bool(title02[i] > 96 ? 1 : 0)); + vector<bool> vec03_ref; + for (size_t i = 0; i < N3; ++i) + vec03_ref.push_back(bool(title03[i] > 96 ? 1 : 0)); + vector<bool> vec04_ref; + for (size_t i = 0; i < N4; ++i) + vec04_ref.push_back(bool(title04[i] > 96 ? 1 : 0)); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_vector vec01(alloc01); + size01 = vec01.size(); + personality01 = vec01.get_allocator().get_personality(); + my_vector vec02(alloc02); + size02 = vec02.size(); + personality02 = vec02.get_allocator().get_personality(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + VERIFY( vec01.get_allocator().get_personality() == personality02 ); + VERIFY( vec02.get_allocator().get_personality() == personality01 ); + + my_vector vec03(alloc02); + size01 = vec03.size(); + personality01 = vec03.get_allocator().get_personality(); + my_vector vec04(vec02_ref.begin(), vec02_ref.end(), alloc01); + size02 = vec04.size(); + personality02 = vec04.get_allocator().get_personality(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), vec02_ref.begin()) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + VERIFY( vec03.get_allocator().get_personality() == personality02 ); + VERIFY( vec04.get_allocator().get_personality() == personality01 ); + + my_vector vec05(vec01_ref.begin(), vec01_ref.end(), alloc01); + size01 = vec05.size(); + personality01 = vec05.get_allocator().get_personality(); + my_vector vec06(vec02_ref.begin(), vec02_ref.end(), alloc02); + size02 = vec06.size(); + personality02 = vec06.get_allocator().get_personality(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), vec02_ref.begin()) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), vec01_ref.begin()) ); + VERIFY( vec05.get_allocator().get_personality() == personality02 ); + VERIFY( vec06.get_allocator().get_personality() == personality01 ); + + my_vector vec07(vec01_ref.begin(), vec01_ref.end(), alloc02); + size01 = vec07.size(); + personality01 = vec07.get_allocator().get_personality(); + my_vector vec08(vec03_ref.begin(), vec03_ref.end(), alloc01); + size02 = vec08.size(); + personality02 = vec08.get_allocator().get_personality(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), vec03_ref.begin()) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), vec01_ref.begin()) ); + VERIFY( vec07.get_allocator().get_personality() == personality02 ); + VERIFY( vec08.get_allocator().get_personality() == personality01 ); + + my_vector vec09(vec03_ref.begin(), vec03_ref.end(), alloc01); + size01 = vec09.size(); + personality01 = vec09.get_allocator().get_personality(); + my_vector vec10(vec04_ref.begin(), vec04_ref.end(), alloc02); + size02 = vec10.size(); + personality02 = vec10.get_allocator().get_personality(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), vec04_ref.begin()) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), vec03_ref.begin()) ); + VERIFY( vec09.get_allocator().get_personality() == personality02 ); + VERIFY( vec10.get_allocator().get_personality() == personality01 ); + + my_vector vec11(vec04_ref.begin(), vec04_ref.end(), alloc02); + size01 = vec11.size(); + personality01 = vec11.get_allocator().get_personality(); + my_vector vec12(vec01_ref.begin(), vec01_ref.end(), alloc01); + size02 = vec12.size(); + personality02 = vec12.get_allocator().get_personality(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), vec01_ref.begin()) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), vec04_ref.begin()) ); + VERIFY( vec11.get_allocator().get_personality() == personality02 ); + VERIFY( vec12.get_allocator().get_personality() == personality01 ); + + my_vector vec13(vec03_ref.begin(), vec03_ref.end(), alloc01); + size01 = vec13.size(); + personality01 = vec13.get_allocator().get_personality(); + my_vector vec14(vec03_ref.begin(), vec03_ref.end(), alloc02); + size02 = vec14.size(); + personality02 = vec14.get_allocator().get_personality(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), vec03_ref.begin()) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), vec03_ref.begin()) ); + VERIFY( vec13.get_allocator().get_personality() == personality02 ); + VERIFY( vec14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/requirements/citerators.cc new file mode 100644 index 000000000..9f4783b74 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <vector> +#include <testsuite_containers.h> + +int main() +{ + typedef std::vector<bool> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/requirements/dr438/constructor.cc new file mode 100644 index 000000000..9a815ec7d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/requirements/dr438/constructor.cc @@ -0,0 +1,27 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + +// { dg-do compile } + +#include <vector> + +void f() +{ + std::vector<bool> vb(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc new file mode 100644 index 000000000..557b329f3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc @@ -0,0 +1,61 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999, 2002, 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.4.2 vector capacity + +#include <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +template<typename T> + struct A { }; + +struct B { }; + +void test01() +{ + // non POD types + bool test __attribute__((unused)) = true; + std::vector< A<B> > vec01; + typedef std::vector< A<B> >::size_type size_type; + + size_type sz01 = vec01.capacity(); + vec01.reserve(100); + size_type sz02 = vec01.capacity(); + VERIFY( sz02 >= sz01 ); + + sz01 = vec01.size() + 5; + vec01.resize(sz01); + sz02 = vec01.size(); + VERIFY( sz01 == sz02 ); + + sz01 = vec01.size() - 5; + vec01.resize(sz01); + sz02 = vec01.size(); + VERIFY( sz01 == sz02 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc new file mode 100644 index 000000000..1cf0cae98 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc @@ -0,0 +1,102 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999, 2002, 2003, 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.4.2 vector capacity + +#include <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +using __gnu_test::copy_tracker; +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; +using __gnu_test::copy_constructor; +using __gnu_test::assignment_operator; +using __gnu_test::destructor; + +// Verifies basic functionality of reserve() with forced reallocation. +void +test_reserve() +{ + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(3); + const X::size_type old_size = a.size(); + const X::size_type old_capacity = a.capacity(); + const X::size_type new_capacity = old_capacity + 10; + T::reset(); + + a.reserve(new_capacity); + + // [23.2.4.1 (2)] + VERIFY(new_capacity <= a.capacity()); + // [23.2.4.1 (3)] + VERIFY(old_size == a.size()); + VERIFY(copy_constructor::count() <= old_size); + VERIFY(destructor::count() <= old_size); + } + // check for memory leaks + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); +} + +// Verifies that reserve() with reallocation offers the strong +// exception guarantee. +void +test_reserve_exception_guarantee() +{ + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + const X::size_type old_size __attribute__((unused)) = a.size(); + const X::size_type old_capacity = a.capacity(); + const X::size_type new_capacity = old_capacity + 10; + T::reset(); + copy_constructor::throw_on(3); + + try + { + a.reserve(new_capacity); + VERIFY(false); + } + catch (...) + { + } + + VERIFY(old_capacity == a.capacity()); + VERIFY(copy_constructor::count() == destructor::count()+1); + } + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); +} + +int main() +{ + test_reserve(); + test_reserve_exception_guarantee(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc new file mode 100644 index 000000000..c48e474e9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc @@ -0,0 +1,50 @@ +// Copyright (C) 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.4.2 vector capacity [lib.vector.capacity] + +#include <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + vector<int> v; + + try + { + v.resize(size_t(-1)); + } + catch(const std::length_error&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc new file mode 100644 index 000000000..72fac56c2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc @@ -0,0 +1,37 @@ +// Copyright (C) 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.4.2 vector capacity [lib.vector.capacity] + +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> v; + + VERIFY( v.max_size() == v.get_allocator().max_size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc new file mode 100644 index 000000000..737108b49 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2010 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/>. + +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/44190 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> v; + v.resize(10); + VERIFY( v.size() <= v.capacity() ); +} + +int main() +{ + + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc new file mode 100644 index 000000000..b1b2c7d48 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc @@ -0,0 +1,78 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999, 2002, 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.4.2 vector capacity + +#include <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +// libstdc++/8230 +void test02() +{ + bool test __attribute__((unused)) = true; + { + std::vector<int> array; + const std::size_t size = array.max_size(); + try + { + array.reserve(size); + } + catch (const std::length_error& error) + { + test &= false; + } + catch (const std::bad_alloc& error) + { + test &= true; + } + catch (...) + { + test &= false; + } + VERIFY( test ); + } + + { + std::vector<int> array; + const std::size_t size = array.max_size() + 1; + try + { + array.reserve(size); + } + catch (const std::length_error& error) + { + test &= true; + } + catch (...) + { + test &= false; + } + VERIFY( test ); + } +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc new file mode 100644 index 000000000..c8ce77b63 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector<copycounter> a(40); + copycounter::copycount = 0; + + a.reserve(50); + VERIFY( copycounter::copycount == 0 ); + + a.reserve(200); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc new file mode 100644 index 000000000..168df7a4a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc @@ -0,0 +1,60 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999, 2002, 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.4.2 vector capacity + +// XXX This test will not work for irix6 because of bug(s) in libc malloc +// XXX for very large allocations. However -lmalloc seems to work. +// See http://gcc.gnu.org/ml/libstdc++/2002-12/msg00131.html +// { dg-options "-lmalloc" { target mips*-*-irix6* } } + +// This fails on some versions of Darwin 8 because malloc doesn't return +// NULL even if an allocation fails (filed as Radar 3884894). +// { dg-do run { xfail *-*-darwin8.[0-4].* } } + +#include <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::vector<int> v; + try + { + v.resize(v.max_size()); + v[v.max_size() - 1] = 2002; + } + catch (const std::bad_alloc& error) + { + test = true; + } + catch (...) + { + test = false; + } + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc new file mode 100644 index 000000000..5ba026dbe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// 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 <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<copycounter> a; + copycounter::copycount = 0; + a.resize(10); + a.resize(98); + a.resize(99); + a.resize(100); + VERIFY( copycounter::copycount == 0 ); + + a.resize(99); + a.resize(0); + VERIFY( copycounter::copycount == 0 ); + + a.resize(100); + VERIFY( copycounter::copycount == 0 ); + + a.clear(); + VERIFY( copycounter::copycount == 0 ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc new file mode 100644 index 000000000..d181168ac --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <vector> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v; + VERIFY( std::distance(v.begin(), v.end()) == 0 ); + + v.resize(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc new file mode 100644 index 000000000..482166cab --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <vector> +#include <testsuite_hooks.h> + +// libstdc++/42573 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> v(100); + v.push_back(1); + v.push_back(1); + VERIFY( v.size() < v.capacity() ); + v.shrink_to_fit(); + VERIFY( v.size() == v.capacity() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/check_construct_destroy.cc b/libstdc++-v3/testsuite/23_containers/vector/check_construct_destroy.cc new file mode 100644 index 000000000..d84228c88 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/check_construct_destroy.cc @@ -0,0 +1,76 @@ +// 2004-07-26 Matt Austern <austern@apple.com> +// +// Copyright (C) 2003, 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 <vector> +#include <testsuite_allocator.h> + +using namespace __gnu_test; + +int main() +{ + typedef std::vector<int, tracker_allocator<int> > Container; + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + Container c; + ok = check_construct_destroy("empty container", 0, 0) && ok; + } + ok = check_construct_destroy("empty container", 0, 0) && ok; + + + tracker_allocator_counter::reset(); + { + Container c(arr10, arr10 + 10); + ok = check_construct_destroy("Construct from range", 10, 0) && ok; + } + ok = check_construct_destroy("Construct from range", 10, 10) && ok; + + { + Container c(arr10, arr10 + 10); + c.reserve(100); + tracker_allocator_counter::reset(); + c.insert(c.begin(), arr10[0]); + ok = check_construct_destroy("Insert element", 1, 0) && ok; + } + ok = check_construct_destroy("Insert element", 1, 11) && ok; + + { + Container c(arr10, arr10 + 10); + c.reserve(100); + tracker_allocator_counter::reset(); + c.insert(c.begin() + 5, arr10, arr10+3); + ok = check_construct_destroy("Insert short range", 3, 0) && ok; + } + ok = check_construct_destroy("Insert short range", 3, 13) && ok; + + { + Container c(arr10, arr10 + 10); + c.reserve(100); + tracker_allocator_counter::reset(); + c.insert(c.begin() + 7, arr10, arr10+10); + ok = check_construct_destroy("Insert long range", 10, 0) && ok; + } + ok = check_construct_destroy("Insert long range", 10, 20) && ok; + + return ok ? 0 : 1; +} + diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/1.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/1.cc new file mode 100644 index 000000000..f17de5c57 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/1.cc @@ -0,0 +1,47 @@ +// 1999-06-29 bkoz + +// Copyright (C) 1999-2001, 2002, 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.4.1 vector constructors, copy, and assignment + +#include <vector> +#include <string> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +template<typename T> + struct A { }; + +struct B { }; + +void test01() +{ + // 1 + std::vector< A<B> > vec01; + std::vector< A<B> > vec02(5); + typedef std::vector< A<B> >::size_type size_type; + + vec01 = vec02; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/2.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/2.cc new file mode 100644 index 000000000..24add08ab --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/2.cc @@ -0,0 +1,48 @@ +// 1999-06-29 bkoz + +// Copyright (C) 1999-2001, 2002, 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.4.1 vector constructors, copy, and assignment + +#include <vector> +#include <string> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +template<typename T> + struct A { }; + +struct B { }; + +// 2 +template class std::vector<double>; +template class std::vector< A<B> >; + +// libstdc++/102 +void test02() +{ + std::vector<int> v1; + std::vector<int> v2(v1); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/3.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/3.cc new file mode 100644 index 000000000..03859ece7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/3.cc @@ -0,0 +1,53 @@ +// 1999-06-29 bkoz + +// Copyright (C) 1999-2001, 2002, 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.4.1 vector constructors, copy, and assignment + +#include <vector> +#include <string> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +// test range constructors and range-fill constructor +void +test03() +{ + bool test __attribute__((unused)) = true; + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + const int B[] = {7, 7, 7, 7, 7}; + const int N = sizeof(A) / sizeof(int); + const int M = sizeof(B) / sizeof(int); + + std::vector<int> v3(A, A + N); + VERIFY(std::equal(v3.begin(), v3.end(), A)); + + std::vector<int> v4(v3.begin(), v3.end()); + VERIFY(std::equal(v4.begin(), v4.end(), A)); + + std::vector<int> v5(M, 7); + VERIFY(std::equal(v5.begin(), v5.end(), B)); + VERIFY(std::equal(B, B + M, v5.begin())); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/4.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/4.cc new file mode 100644 index 000000000..27d496ac9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/4.cc @@ -0,0 +1,584 @@ +// 1999-06-29 bkoz + +// Copyright (C) 1999-2001, 2002, 2003, 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.4.1 vector constructors, copy, and assignment + +#include <vector> +#include <string> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +using __gnu_test::copy_tracker; +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; +using __gnu_test::copy_constructor; +using __gnu_test::assignment_operator; + +// @fn test_default_ctor_exception_gurantee This test verifies that if +// one of the vector's contained objects throws an exception from its +// constructor while the vector is being constructed and filled with +// default values, all memory is returned to the allocator whence it +// came. +void +test_default_ctor_exception_gurantee() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + copy_tracker::reset(); + copy_constructor::throw_on(3); + tracker_allocator_counter::reset(); + + // run test + try + { + T ref; + X a(7, ref); + VERIFY(false); + } + catch (...) + { + } + + // assert postconditions + VERIFY( tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count() ); + + // teardown +} + +// @fn test_copy_ctor_exception_gurantee This test verifies that if +// one of the vector's contained objects throws an exception from its +// constructor while the vector is being copy constructed, all memory +// is returned to the allocator whence it came. +void +test_copy_ctor_exception_gurantee() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + copy_tracker::reset(); + copy_constructor::throw_on(3); + + // run test + try + { + X u(a); + VERIFY(false); + } + catch (...) + { + } + } + + // assert postconditions + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +// operator=() +// +// case 1: lhs.size() > rhs.size() +// case 2: lhs.size() < rhs.size() < lhs.capacity() +// case 3: lhs.capacity() < rhs.size() +// +void +test_assignment_operator_1() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X r(9); + X a(r.size() - 2); + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // preconditions + VERIFY(r.size() > a.size()); + + // run test + r = a; + + // assert postconditions + VERIFY(r == a); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_assignment_operator_2() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X r(1); + r.reserve(17); + X a(r.size() + 7); + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // preconditions + VERIFY(r.size() < a.size()); + VERIFY(a.size() < r.capacity()); + + // run test + r = a; + + // assert postconditions + VERIFY(r == a); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_assignment_operator_3() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X r(1); + X a(r.capacity() + 7); + copy_tracker::reset(); + + // preconditions + VERIFY(r.capacity() < a.size()); + + // run test + r = a; + + // assert postconditions + VERIFY(r == a); + } + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_assignment_operator_3_exception_guarantee() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X r(1); + X a(r.capacity() + 7); + copy_tracker::reset(); + copy_constructor::throw_on(3); + + // preconditions + VERIFY(r.capacity() < a.size()); + + // run test + try + { + r = a; + VERIFY(false); + } + catch (...) + { + } + } + + // assert postconditions + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +// fill assign() +// +// case 1: [23.2.4.1 (3)] n <= size() +// case 2: [23.2.4.1 (3)] size() < n <= capacity() +// case 3: [23.2.4.1 (3)] n > capacity() +// case 4: [23.2.4.1 (3)] n > capacity(), exception guarantees +// case 5: [23.1.1 (9)] fill assign disguised as a range assign +// +void +test_fill_assign_1() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X a(7); + X::size_type old_size = a.size(); + X::size_type new_size = old_size - 2; + const T t; + + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // run test + a.assign(new_size, t); + + // assert postconditions + VERIFY(a.size() == new_size); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_fill_assign_2() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X a(7); + a.reserve(11); + X::size_type old_size = a.size(); + X::size_type old_capacity = a.capacity(); + X::size_type new_size = old_size + 2; + const T t; + + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // assert preconditions + VERIFY(old_size < new_size); + VERIFY(new_size <= old_capacity); + + // run test + a.assign(new_size, t); + + // assert postconditions + VERIFY(a.size() == new_size); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_fill_assign_3() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + X::size_type old_capacity = a.capacity(); + X::size_type new_size = old_capacity + 4; + const T t; + + copy_tracker::reset(); + + // assert preconditions + VERIFY(new_size > old_capacity); + + // run test + a.assign(new_size, t); + + // assert postconditions + VERIFY(a.size() == new_size); + } + + VERIFY(tracker_allocator_counter::get_allocation_count() > 0); + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_fill_assign_3_exception_guarantee() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + X::size_type old_size = a.size(); + X::size_type old_capacity = a.capacity(); + X::size_type new_size = old_capacity + 4; + const T t; + + copy_tracker::reset(); + copy_constructor::throw_on(3); + + // assert preconditions + VERIFY(new_size > old_capacity); + + // run test + try + { + a.assign(new_size, t); + VERIFY(false); + } + catch (...) + { + } + + // assert postconditions + VERIFY(a.size() == old_size); + VERIFY(a.capacity() == old_capacity); + } + + VERIFY(tracker_allocator_counter::get_allocation_count() > 0); + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_fill_assign_4() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X a(7); + X::size_type old_size = a.size(); + X::size_type new_size = old_size - 2; + X::size_type new_value = 117; + + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // run test + a.assign(new_size, new_value); + + // assert postconditions + VERIFY(a.size() == new_size); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +// range assign() +// +// case 1: [23.2.4.1 (2)] input iterator +// case 2: [23.2.4.1 (2)] forward iterator, distance(first, last) <= size() +// case 3: [23.2.4.1 (2)] +// forward iterator, size() < distance(first, last) <= capacity() +// case 4: [23.2.4.1 (2)] forward iterator, distance(first, last) > capacity() +// case 5: [23.2.4.1 (2)] +// forward iterator, distance(first, last) > capacity(), +// exception guarantees +void +test_range_assign_1() +{ + // @TODO +} + +void +test_range_assign_2() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X a(7); + X b(3); + + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // assert preconditions + VERIFY(b.size() < a.capacity()); + + // run test + a.assign(b.begin(), b.end()); + + // assert postconditions + VERIFY(a.size() == b.size()); + VERIFY(a == b); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_range_assign_3() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + X a(7); + a.reserve(a.size() + 7); + X b(a.size() + 3); + + copy_tracker::reset(); + tracker_allocator_counter::reset(); + + // assert preconditions + VERIFY(a.size() < b.size()); + VERIFY(b.size() < a.capacity()); + + // run test + a.assign(b.begin(), b.end()); + + // assert postconditions + VERIFY(a.size() == b.size()); + VERIFY(a == b); + VERIFY(tracker_allocator_counter::get_allocation_count() == 0); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_range_assign_4() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + X b(a.capacity() + 7); + + copy_tracker::reset(); + + // assert preconditions + VERIFY(b.size() > a.capacity()); + + // run test + a.assign(b.begin(), b.end()); + + // assert postconditions + VERIFY(a.size() == b.size()); + VERIFY(a == b); + } + VERIFY(tracker_allocator_counter::get_allocation_count() > 0); + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + +void +test_range_assign_4_exception_guarantee() +{ + // setup + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + X b(a.capacity() + 7); + + copy_tracker::reset(); + copy_constructor::throw_on(3); + + // assert preconditions + VERIFY(b.size() > a.capacity()); + + // run test + try + { + a.assign(b.begin(), b.end()); + VERIFY(false); + } + catch (...) + { + } + } + + // assert postconditions + VERIFY(tracker_allocator_counter::get_allocation_count() > 0); + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); + + // teardown + copy_tracker::reset(); + tracker_allocator_counter::reset(); +} + + +int main() +{ + test_default_ctor_exception_gurantee(); + test_copy_ctor_exception_gurantee(); + test_assignment_operator_1(); + test_assignment_operator_2(); + test_assignment_operator_3(); + test_assignment_operator_3_exception_guarantee(); + test_fill_assign_1(); + test_fill_assign_2(); + test_fill_assign_3(); + test_fill_assign_3_exception_guarantee(); + test_fill_assign_4(); + test_range_assign_1(); + test_range_assign_2(); + test_range_assign_3(); + test_range_assign_4(); + test_range_assign_4_exception_guarantee(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/6513.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/6513.cc new file mode 100644 index 000000000..b469fdcab --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/6513.cc @@ -0,0 +1,39 @@ +// 1999-06-29 bkoz + +// Copyright (C) 1999-2001, 2002, 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.4.1 vector constructors, copy, and assignment + +#include <vector> +#include <string> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +// libstdc++/6513 +void test04() +{ + const char* c_strings[5] = { "1", "2", "3", "4", "5" }; + std::vector<std::string> strings(c_strings, c_strings + 5); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/clear_allocator.cc new file mode 100644 index 000000000..18a2f1a02 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/clear_allocator.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004, 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 <vector> +#include <ext/new_allocator.h> + +using namespace std; +using __gnu_cxx::new_allocator; + +template<typename T> + class clear_alloc : public new_allocator<T> + { + public: + + template <typename T1> + struct rebind + { typedef clear_alloc<T1> other; }; + + virtual void clear() throw() + { } + + clear_alloc() throw() + { } + + clear_alloc(clear_alloc const&) throw() : new_allocator<T>() + { } + + template<typename T1> + clear_alloc(clear_alloc<T1> const&) throw() + { } + + virtual ~clear_alloc() throw() + { this->clear(); } + + T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0) + { + this->clear(); + return new_allocator<T>::allocate(n, hint); + } + + void deallocate(T *ptr, typename new_allocator<T>::size_type n) + { + this->clear(); + new_allocator<T>::deallocate(ptr, n); + } + }; + +template<typename Container> + void Check_Container() + { + Container* pic = new Container; + int x = 230; + + while (x--) + { + pic->push_back(x); + } + + pic->get_allocator(); + + // The following has led to infinite recursions or cores. + pic->clear(); + + delete pic; + } + + +int main() +{ + Check_Container<std::vector<int, clear_alloc<int> > >(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc new file mode 100644 index 000000000..a33ba1ad6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/cons_size.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 <vector> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/moveable.cc new file mode 100644 index 000000000..8807ad9b4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/moveable.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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/>. + + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on vector (via swap). If the implementation changed +// this test may begin to fail. + +#include <vector> +#include <utility> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> a,b; + a.push_back(1); + b = std::move(a); + VERIFY( b.size() == 1 && b[0] == 1 && a.size() == 0 ); + + std::vector<int> c(std::move(b)); + VERIFY( c.size() == 1 && c[0] == 1 ); + VERIFY( b.size() == 0 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::vector<bool> a,b; + a.push_back(1); + b = std::move(a); + VERIFY( b.size() == 1 && b[0] == 1 && a.size() == 0 ); + + std::vector<bool> c(std::move(b)); + VERIFY( c.size() == 1 && c[0] == 1 ); + VERIFY( b.size() == 0 ); +} + +int main(void) +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/moveable2.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/moveable2.cc new file mode 100644 index 000000000..ab04ccf0c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/moveable2.cc @@ -0,0 +1,55 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2007, 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 <vector> +#include <iterator> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; +typedef std::vector<rvalstruct> test_type; + +// Empty constructor doesn't require a copy constructor +void +test01() +{ test_type d; } + +// Constructing from a range that returns rvalue references doesn't +// require a copy constructor. +void +test02(rvalstruct* begin, rvalstruct* end) +{ + test_type d(std::make_move_iterator(begin), std::make_move_iterator(end)); +} + +// Constructing from a input iterator range that returns rvalue +// references doesn't require a copy constructor either. +void +test03(input_iterator_wrapper<rvalstruct> begin, + input_iterator_wrapper<rvalstruct> end) +{ + test_type d(std::make_move_iterator(begin), std::make_move_iterator(end)); +} + +// Neither does destroying one. +void +test04(test_type* d) +{ delete d; } diff --git a/libstdc++-v3/testsuite/23_containers/vector/data_access/1.cc b/libstdc++-v3/testsuite/23_containers/vector/data_access/1.cc new file mode 100644 index 000000000..ae829984a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/data_access/1.cc @@ -0,0 +1,50 @@ +// 2005-08-29 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 <vector> +#include <testsuite_hooks.h> + +// libstdc++/23578 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::vector<int> vector_type; + + { + const int A[] = { 0, 1, 2, 3, 4 }; + vector_type v(A, A + 5); + VERIFY( v.data() == &v.front() ); + int* pi = v.data(); + VERIFY( *pi == 0 ); + } + + { + const int A[] = { 4, 3, 2, 1, 0 }; + const vector_type cv(A, A + 5); + VERIFY( cv.data() == &cv.front() ); + const int* pci = cv.data(); + VERIFY( *pci == 4 ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/52433.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/52433.cc new file mode 100644 index 000000000..f1f5917d1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/52433.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2012 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/>. +// +// { dg-require-debug-mode "" } +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// PR libstdc++/52433 + +#include <vector> + +struct X +{ + std::vector<int>::iterator i; + + X() = default; + X(const X&) = default; + X(X&&) = default; + X& operator=(const X&) = default; + X& operator=(X&&) = default; +}; + +X test01() +{ + X x; + x = X(); + return x; +} + diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/assign1_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/assign1_neg.cc new file mode 100644 index 000000000..ff9c5a24b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign1<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/assign2_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/assign2_neg.cc new file mode 100644 index 000000000..4384a97bd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign2<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/assign3_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/assign3_neg.cc new file mode 100644 index 000000000..9cb7ea6f9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign3<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_neg.cc new file mode 100644 index 000000000..8e3d3be9c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_assign1<__gnu_debug::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/construct1_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/construct1_neg.cc new file mode 100644 index 000000000..dc0b4a22e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/construct1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/construct2_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/construct2_neg.cc new file mode 100644 index 000000000..13757a1fa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/construct2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct2<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/construct3_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/construct3_neg.cc new file mode 100644 index 000000000..661af4382 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/construct3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct3<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/construct4_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/construct4_neg.cc new file mode 100644 index 000000000..ec33a5813 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/construct4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_construct1<__gnu_debug::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/insert1_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/insert1_neg.cc new file mode 100644 index 000000000..2ec0d9e02 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/insert1_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/insert2_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/insert2_neg.cc new file mode 100644 index 000000000..011ad4c0c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/insert2_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert2<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/insert3_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/insert3_neg.cc new file mode 100644 index 000000000..4dab133b5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/insert3_neg.cc @@ -0,0 +1,33 @@ +// Copyright (C) 2010 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/>. +// +// { dg-require-debug-mode "" } +// { dg-do run { xfail *-*-* } } + +#include <vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert3<std::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/insert4_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/insert4_neg.cc new file mode 100644 index 000000000..684ebb598 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/insert4_neg.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2010 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/>. +// +// { dg-do run { xfail *-*-* } } + +#include <debug/vector> +#include <debug/checks.h> + +void test01() +{ + __gnu_test::check_insert1<__gnu_debug::vector<int> >(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/1.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/1.cc new file mode 100644 index 000000000..0111efe48 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/1.cc @@ -0,0 +1,59 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003, 2004, 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/>. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Assignment +void test01() +{ + vector<int> v1; + vector<int> v2; + + vector<int>::iterator i = v1.end(); + VERIFY(!i._M_dereferenceable() && !i._M_singular()); + + v1 = v2; + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(v2.begin(), v2.end()); + VERIFY(i._M_singular()); + + i = v1.end(); + v1.assign(17, 42); + VERIFY(i._M_singular()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/2.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/2.cc new file mode 100644 index 000000000..9652ffb53 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/2.cc @@ -0,0 +1,64 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003, 2004, 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/>. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Resize +void test02() +{ + vector<int> v(10, 17); + v.reserve(20); + + vector<int>::iterator before = v.begin() + 6; + vector<int>::iterator at = before + 1; + vector<int>::iterator after = at + 1; + + // Shrink + v.resize(7); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + VERIFY(after._M_singular()); + + // Grow, without reallocation + before = v.begin() + 6; + v.resize(17); + VERIFY(before._M_dereferenceable()); + + // Grow, with reallocation + v.resize(42); + VERIFY(before._M_singular()); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/3.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/3.cc new file mode 100644 index 000000000..df8759c52 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/3.cc @@ -0,0 +1,89 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003, 2004, 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/>. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Insert +void test03() +{ + vector<int> v(10, 17); + v.reserve(30); + + // Insert a single element + vector<int>::iterator before = v.begin() + 6; + vector<int>::iterator at = before + 1; + vector<int>::iterator after = at; + at = v.insert(at, 42); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Insert multiple copies + before = v.begin() + 6; + at = before + 1; + v.insert(at, 3, 42); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // Insert iterator range + static int data[] = { 2, 3, 5, 7 }; + before = v.begin() + 6; + at = before + 1; + v.insert(at, &data[0], &data[0] + 4); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // Insert with reallocation + before = v.begin() + 6; + at = before + 1; + v.insert(at, 30, 17); + VERIFY(before._M_singular()); + VERIFY(at._M_singular()); + + // Single insert with reallocation + vector<int> v2; + v2.reserve(100); + at = v2.begin(); + v2.insert(at, 100, 17); + at = v2.end() - 1; + before = v2.begin(); + VERIFY(at._M_dereferenceable()); + VERIFY(before._M_dereferenceable()); + at = v2.insert(at, 42); + VERIFY(at._M_dereferenceable()); + VERIFY(before._M_singular()); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/4.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/4.cc new file mode 100644 index 000000000..569530693 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/invalidation/4.cc @@ -0,0 +1,66 @@ +// Vector iterator invalidation tests + +// Copyright (C) 2003, 2004, 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/>. + +// We need to be pedantic about reallocations for this testcase to be correct. +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#ifndef _GLIBCXX_DEBUG_PEDANTIC +# define _GLIBCXX_DEBUG_PEDANTIC 1 +#endif + +#include <debug/vector> +#include <testsuite_hooks.h> + +using __gnu_debug::vector; + +bool test = true; + +// Erase +void test04() +{ + vector<int> v(20, 42); + + // Single element erase + vector<int>::iterator before = v.begin(); + vector<int>::iterator at = before + 3; + vector<int>::iterator after = at; + at = v.erase(at); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_dereferenceable()); + VERIFY(after._M_singular()); + + // Multiple element erase + before = v.begin(); + at = before + 3; + v.erase(at, at + 3); + VERIFY(before._M_dereferenceable()); + VERIFY(at._M_singular()); + + // clear() + before = v.begin(); + VERIFY(before._M_dereferenceable()); + v.clear(); + VERIFY(before._M_singular()); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/multithreaded_swap.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/multithreaded_swap.cc new file mode 100644 index 000000000..b2a50aa21 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/multithreaded_swap.cc @@ -0,0 +1,100 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-debug-mode "" } +// Copyright (C) 2010 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/>. +// + +// This test check for potential deadlock when swaping sequences in debug +// mode as it requires acquiring 2 locks at the same time. + +#include <vector> +#include <thread> +#include <functional> +#include <testsuite_hooks.h> + +// The following function mimic the one in src/debug.cc to associate a mutex +// to a given safe sequence instance. +size_t +get_index(std::vector<int>& v) +{ + const size_t mask = 0xf; + // We have to check the address of the internal safe sequence that starts + // after the normal vector memory footprint that is to say a 3 pointers + // offset: + void* __address = reinterpret_cast<char*>(&v) + 3 * sizeof(void*); + return std::_Hash_impl::hash(__address) & mask; +} + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + vector<int> v1, v2; + vector<shared_ptr<vector<int> > > vs; + vector<int> *pv3 = 0, *pv4 = 0; + const int nb_attempts = 100; + for (int i = 0; i != nb_attempts; ++i) + { + vs.push_back(shared_ptr<vector<int> >(new vector<int>())); + if (!pv3) + { + if (get_index(*vs.back()) == get_index(v1)) + pv3 = vs.back().get(); + } + else if (!pv4) + { + if (get_index(*vs.back()) == get_index(v2)) + { + pv4 = vs.back().get(); + break; + } + } + } + + if (!pv3 || !pv4) + // Maybe an other time... + return; + + vector<int> &v3 = *pv3, &v4 = *pv4; + + // v1 and v3 shares the same mutex instance, like v2 and v4 + // thread t1 lock v1 and v2 + thread t1([&v1, &v2]() + { + for (int i = 0; i != 1000; ++i) + v1.swap(v2); + }); + // thread t2 lock v4 and v3 + thread t2([&v3, &v4]() + { + for (int i = 0; i != 1000; ++i) + v4.swap(v3); + }); + t2.join(); + t1.join(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug_mode_requires_reallocation-1.cc b/libstdc++-v3/testsuite/23_containers/vector/debug_mode_requires_reallocation-1.cc new file mode 100644 index 000000000..3f65119a7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug_mode_requires_reallocation-1.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2008, 2009, 2010 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/>. + +// NB: This issue affected only debug-mode. + +#include <vector> +#include <algorithm> +#include <iterator> + +// http://gcc.gnu.org/ml/libstdc++/2008-05/msg00039.html +void test01() +{ + typedef std::vector<unsigned> array_t; + typedef std::back_insert_iterator<array_t> bii_t; + + array_t a; + + // Push 5 elements. + a.push_back(0); + a.push_back(1); + a.push_back(2); + a.push_back(3); + a.push_back(4); + // Ensure that there is enough space for other two elements. + // (2 + 5 = 7) + if (a.capacity() < 7) + a.reserve(7); + // Add two new elements. + std::copy(a.begin(), a.begin() + 2, bii_t(a)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug_mode_requires_reallocation-2.cc b/libstdc++-v3/testsuite/23_containers/vector/debug_mode_requires_reallocation-2.cc new file mode 100644 index 000000000..56bc10909 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug_mode_requires_reallocation-2.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2008, 2009, 2010 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/>. + +// NB: This issue affected only debug-mode, in pedantic mode. + +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#include <vector> +#include <algorithm> +#include <iterator> + +// http://gcc.gnu.org/ml/libstdc++/2008-05/msg00046.html +void test01() +{ + typedef std::vector<unsigned> array_t; + typedef std::back_insert_iterator<array_t> bii_t; + + array_t a; + + // Push 5 elements. + a.push_back(0); + a.push_back(1); + a.push_back(2); + a.push_back(3); + a.push_back(4); + // Ensure that there is enough space for other two elements. + // (2 + 5 = 7) + if (a.capacity() < 7) + a.reserve(7); + // Add two new elements. + std::copy(a.begin(), a.begin() + 2, bii_t(a)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/element_access/1.cc b/libstdc++-v3/testsuite/23_containers/vector/element_access/1.cc new file mode 100644 index 000000000..511620cac --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/element_access/1.cc @@ -0,0 +1,61 @@ +// 2000-09-06 +// bkoz + +// Copyright (C) 2000, 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.4 vector + +#include <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +template<typename T> +struct A { }; + +struct B { }; + +// http://gcc.gnu.org/ml/libstdc++/2000-09/msg00002.html +bool test01() +{ + bool test __attribute__((unused)) = true; + std::vector< A<B> > vec01; + std::vector< A<B> > vec02(5); + typedef std::vector< A<B> >::size_type size_type; + typedef std::vector< A<B> >::reference reference; + + try + { + reference r01 __attribute__((unused)) = vec01.at(6); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch(std::out_of_range& err) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/citerators.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/citerators.cc new file mode 100644 index 000000000..4037536ec --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/citerators.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2008, 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 <vector> +#include <testsuite_hooks.h> +#include <ext/extptr_allocator.h> + +// Ensures equivalence of iterators based on low-level comparison +// between const / non-const Pointer types. +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > v(7); + VERIFY( v.cbegin() == v.begin() ); + VERIFY( v.cend() == v.end() ); + VERIFY( v.crbegin() == v.rbegin() ); + VERIFY( v.crend() == v.rend() ); + VERIFY( v.cbegin() != v.cend() ); + VERIFY( v.crbegin() != v.crend() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/data_access.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/data_access.cc new file mode 100644 index 000000000..a74f44c40 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/data_access.cc @@ -0,0 +1,53 @@ +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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 <vector> +#include <testsuite_hooks.h> +#include <ext/extptr_allocator.h> + +// libstdc++/23578 +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > vector_type; + + { + const int A[] = { 0, 1, 2, 3, 4 }; + vector_type v(A, A + 5); + VERIFY( v.data() == &v.front() ); + int* pi = &* v.data(); + VERIFY( *pi == 0 ); + } + + { + const int A[] = { 4, 3, 2, 1, 0 }; + const vector_type cv(A, A + 5); + VERIFY( cv.data() == &cv.front() ); + const int* pci = &* cv.data(); + VERIFY( *pci == 4 ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/explicit_instantiation/1.cc new file mode 100644 index 000000000..5f585e449 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/explicit_instantiation/1.cc @@ -0,0 +1,27 @@ +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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 <vector> +#include <ext/extptr_allocator.h> + +// { dg-do compile } + +template class std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> >; diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/explicit_instantiation/3.cc new file mode 100644 index 000000000..8c6d3dc55 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/explicit_instantiation/3.cc @@ -0,0 +1,28 @@ +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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 <vector> +#include <ext/extptr_allocator.h> + +// { dg-do compile } + +// libstdc++/21770 +template class std::vector<int, __gnu_cxx::_ExtPtr_allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/element.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/element.cc new file mode 100644 index 000000000..c12b81cc2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/element.cc @@ -0,0 +1,77 @@ +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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 <vector> +#include <stdexcept> +#include <testsuite_hooks.h> +#include <ext/extptr_allocator.h> + +// General tests element access and manipulation +void test01() +{ + bool test __attribute__((unused)) = true; + + int A[] = { 0, 1, 2, 3, 4 }; + __gnu_cxx::_ExtPtr_allocator<int> alloc; + std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > mv( A, A+5, alloc ); + + VERIFY( mv.size() == 5 ); + VERIFY( mv.front() == 0 ); + VERIFY( mv.back() == 4 ); + VERIFY( mv.at(2) == 2 ); + VERIFY( mv[3] == 3); + mv.front() = 5; + mv.back() = 6; + mv.at(2) = 7; + mv[3] = 8; + VERIFY( mv.size() == 5 ); + VERIFY( mv.front() == 5 ); + VERIFY( mv.back() == 6 ); + VERIFY( mv.at(2) == 7 ); + VERIFY( mv[3] == 8 ); + + try + { + mv.at(100) = 8; + } + catch(std::out_of_range&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } + + const std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > cmv( mv ); + VERIFY( cmv.get_allocator() == mv.get_allocator() ); + VERIFY( mv.size() == 5 ); + VERIFY( mv.front() == 5 ); + VERIFY( mv.back() == 6 ); + VERIFY( mv.at(2) == 7 ); + VERIFY( mv[3] == 8 ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/erase.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/erase.cc new file mode 100644 index 000000000..99008ce54 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/erase.cc @@ -0,0 +1,139 @@ +// Bob Walters 10-2008 + +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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 <vector> +#include <testsuite_hooks.h> +#include <ext/extptr_allocator.h> + +const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15}; +const int A3[] = {0, 2, 3, 4, 10, 11}; +const int A4[] = {4, 10, 11}; +const int A5[] = {4, 10}; +const unsigned int N = sizeof(A) / sizeof(int); +const unsigned int N1 = sizeof(A1) / sizeof(int); +const unsigned int N2 = sizeof(A2) / sizeof(int); +const unsigned int N3 = sizeof(A3) / sizeof(int); +const unsigned int N4 = sizeof(A4) / sizeof(int); +const unsigned int N5 = sizeof(A5) / sizeof(int); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v(A, A + N); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + typedef __gnu_cxx::_ExtPtr_allocator<int> int_alloc_type; + typedef __gnu_cxx::_ExtPtr_allocator< std::vector<int, int_alloc_type> > vec_alloc_type; + typedef std::vector<std::vector<int, int_alloc_type >,vec_alloc_type> vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v, v1, v2, v3, v4, v5; + for (unsigned int i = 0; i < N; ++i) + v.push_back(std::vector<int,int_alloc_type>(1, A[i])); + for (unsigned int i = 0; i < N1; ++i) + v1.push_back(std::vector<int,int_alloc_type>(1, A1[i])); + for (unsigned int i = 0; i < N2; ++i) + v2.push_back(std::vector<int,int_alloc_type>(1, A2[i])); + for (unsigned int i = 0; i < N3; ++i) + v3.push_back(std::vector<int,int_alloc_type>(1, A3[i])); + for (unsigned int i = 0; i < N4; ++i) + v4.push_back(std::vector<int,int_alloc_type>(1, A4[i])); + for (unsigned int i = 0; i < N5; ++i) + v5.push_back(std::vector<int,int_alloc_type>(1, A5[i])); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), v1.begin()) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), v2.begin()) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), v3.begin()) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), v4.begin()) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), v5.begin()) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/insert.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/insert.cc new file mode 100644 index 000000000..6405287d1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/modifiers/insert.cc @@ -0,0 +1,67 @@ +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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 <vector> +#include <testsuite_hooks.h> +#include <ext/extptr_allocator.h> +#include <stdexcept> + +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::_ExtPtr_allocator<int> alloc; + std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > iv(alloc); + VERIFY( iv.get_allocator() == alloc ); + VERIFY( iv.size() == 0 ); + + int A[] = { 0, 1, 2, 3, 4 }; + int B[] = { 5, 5, 5, 5, 5 }; + int C[] = { 6, 7 }; + iv.insert(iv.end(), A, A+5 ); + VERIFY( iv.size() == 5 ); + iv.insert(iv.begin(), 5, 5 ); + iv.insert(iv.begin()+5, 7); + iv.insert(iv.begin()+5, 6); + VERIFY( std::equal(iv.begin(), iv.begin()+5, B )); + VERIFY( std::equal(iv.begin()+5, iv.begin()+7, C)); + VERIFY( std::equal(iv.begin()+7, iv.end(), A)); + VERIFY( iv.size() == 12 ); + + try + { + iv.insert(iv.end(), iv.max_size() + 1, 1); + } + catch(std::length_error&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/resize.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/resize.cc new file mode 100644 index 000000000..432aca27c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/resize.cc @@ -0,0 +1,65 @@ + +// Copyright (C) 2008, 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 <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> +#include <ext/extptr_allocator.h> + + +void test01() +{ + // non POD types + bool test __attribute__((unused)) = true; + + std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > vec01; + typedef std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> >::size_type size_type; + + VERIFY(vec01.empty()); + + const int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + // Test resize of the vector based on reserve + size_type sz01 = vec01.capacity(); + vec01.reserve(100); + size_type sz02 = vec01.capacity(); + VERIFY(sz02 >= sz01); + + // grow/shrink + vec01.assign( A, A+10 ); + sz01 = vec01.size() + 100; + vec01.resize(sz01); + sz02 = vec01.size(); + VERIFY(sz01 == sz02); + VERIFY(std::equal(vec01.begin(), vec01.begin()+10, A)); + + sz01 = vec01.size() - 100; + vec01.resize(sz01); + sz02 = vec01.size(); + VERIFY(sz01 == sz02); + VERIFY(std::equal(vec01.begin(), vec01.end(), A)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc new file mode 100644 index 000000000..66fd2c8bb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/ext_pointer/types/1.cc @@ -0,0 +1,61 @@ +// Test for Container using non-standard pointer types. + +// Copyright (C) 2008, 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/>. + + +// This is a copy of vector/types/1.cc with altered allocator. +// The operator+()s in this test initially failed the test - +// they stress the accurate recognition, by the compiler, +// of _Pointer_adapter's own pointer arithmetic functions, +// which have to match perfectly on the int type to get +// chosen by the compiler when it sees: _Pointer_adapter<T> + int, etc. + +#include <vector> +#include <ext/extptr_allocator.h> + +namespace N +{ + struct X { }; + + template<typename T> + X operator+(T, std::size_t) + { return X(); } + + template<typename T> + X operator-(T, T) + { return X(); } +} + +int main() +{ + std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > v(5); + const std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > w(1); + + v[0]; + w[0]; + v.size(); + v.capacity(); + v.resize(1); + v.insert(v.begin(), N::X()); + v.insert(v.begin(), 1, N::X()); + v.insert(v.begin(), w.begin(), w.end()); + v = w; + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/init-list.cc b/libstdc++-v3/testsuite/23_containers/vector/init-list.cc new file mode 100644 index 000000000..87c485381 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/init-list.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2008, 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/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <vector> +#include <testsuite_allocator.h> + +using namespace __gnu_test; + +int main() +{ + typedef std::vector<int, tracker_allocator<int> > Container; + const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 }; + bool ok = true; + + tracker_allocator_counter::reset(); + { + Container c({ 2, 4, 1 }); + ok = check_construct_destroy("Construct from init-list", 3, 0) && ok; + ok &= (c[0] == 2); + ok &= (c[1] == 4); + } + ok = check_construct_destroy("Construct from init-list", 3, 3) && ok; + + { + Container c(arr10, arr10 + 10); + tracker_allocator_counter::reset(); + c.insert(c.begin() + 7, { 234, 42, 1 }); + ok = check_construct_destroy("Insert init-list", 13, 10) && ok; + ok &= (c[7] == 234); + } + ok = check_construct_destroy("Insert init-list", 13, 23) && ok; + + { + Container c; + tracker_allocator_counter::reset(); + c = { 13, 0, 42 }; + ok = check_construct_destroy("Assign init-list", 3, 0) && ok; + ok &= (c[0] == 13); + } + ok = check_construct_destroy("Assign init-list", 3, 3) && ok; + + return ok ? 0 : 1;; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc new file mode 100644 index 000000000..af0bedcee --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/1.cc @@ -0,0 +1,55 @@ +// 1999-11-09 bkoz + +// Copyright (C) 1999, 2001, 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.4.3 vector modifiers + +#include <vector> +#include "testsuite_hooks.h" + +bool test __attribute__((unused)) = true; + +template<typename T> + struct A { }; + +struct B { }; + +// vector::insert(iterator, inputiterator first, inputiterator last) +void +test01() +{ + // POD types + typedef std::vector<int> vec_POD; + vec_POD vec01; + int i01 = 5; + int* pi01 = &i01; + vec01.insert(vec01.begin(), pi01, pi01 + 1); + + // non POD types + typedef std::vector< A<B> > vec_nonPOD; + vec_nonPOD vec02; + A<B> np01; + A<B>* pnp01 = &np01; + vec02.insert(vec02.begin(), pnp01, pnp01 + 1); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc new file mode 100644 index 000000000..7e152891b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/2.cc @@ -0,0 +1,61 @@ +// 1999-11-09 bkoz + +// Copyright (C) 1999, 2001, 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.4.3 vector modifiers + +#include <vector> +#include "testsuite_hooks.h" + +bool test __attribute__((unused)) = true; + +// test the assign() function +void +test03() +{ + const int K = 417; + const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + 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); + bool test __attribute__((unused)) = true; + + // assign from pointer range + std::vector<int> v3; + v3.assign(A, A + N); + VERIFY(std::equal(v3.begin(), v3.end(), A)); + VERIFY(v3.size() == N); + + // assign from iterator range + std::vector<int> v4; + v4.assign(v3.begin(), v3.end()); + VERIFY(std::equal(v4.begin(), v4.end(), A)); + VERIFY(std::equal(A, A + N, v4.begin())); + + // assign from initializer range with resize + v4.assign(M, K); + VERIFY(std::equal(v4.begin(), v4.end(), B)); + VERIFY(std::equal(B, B + M, v4.begin())); + VERIFY((v4.size() == M) && (M != N)); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc new file mode 100644 index 000000000..2f695e432 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc @@ -0,0 +1,135 @@ +// 2005-11-02 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.4.3 vector modifiers + +#include <vector> +#include <testsuite_hooks.h> + +const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15}; +const int A3[] = {0, 2, 3, 4, 10, 11}; +const int A4[] = {4, 10, 11}; +const int A5[] = {4, 10}; +const unsigned int N = sizeof(A) / sizeof(int); +const unsigned int N1 = sizeof(A1) / sizeof(int); +const unsigned int N2 = sizeof(A2) / sizeof(int); +const unsigned int N3 = sizeof(A3) / sizeof(int); +const unsigned int N4 = sizeof(A4) / sizeof(int); +const unsigned int N5 = sizeof(A5) / sizeof(int); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<int> vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v(A, A + N); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector<std::vector<int> > vec_type; + typedef vec_type::iterator iterator_type; + + vec_type v, v1, v2, v3, v4, v5; + for (unsigned int i = 0; i < N; ++i) + v.push_back(std::vector<int>(1, A[i])); + for (unsigned int i = 0; i < N1; ++i) + v1.push_back(std::vector<int>(1, A1[i])); + for (unsigned int i = 0; i < N2; ++i) + v2.push_back(std::vector<int>(1, A2[i])); + for (unsigned int i = 0; i < N3; ++i) + v3.push_back(std::vector<int>(1, A3[i])); + for (unsigned int i = 0; i < N4; ++i) + v4.push_back(std::vector<int>(1, A4[i])); + for (unsigned int i = 0; i < N5; ++i) + v5.push_back(std::vector<int>(1, A5[i])); + + iterator_type it1 = v.erase(v.begin() + 1); + VERIFY( it1 == v.begin() + 1 ); + VERIFY( v.size() == N1 ); + VERIFY( std::equal(v.begin(), v.end(), v1.begin()) ); + + iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); + VERIFY( it2 == v.begin() + 4 ); + VERIFY( v.size() == N2 ); + VERIFY( std::equal(v.begin(), v.end(), v2.begin()) ); + + iterator_type it3 = v.erase(v.begin() + 6, v.end()); + VERIFY( it3 == v.begin() + 6 ); + VERIFY( v.size() == N3 ); + VERIFY( std::equal(v.begin(), v.end(), v3.begin()) ); + + iterator_type it4 = v.erase(v.begin(), v.begin() + 3); + VERIFY( it4 == v.begin() ); + VERIFY( v.size() == N4 ); + VERIFY( std::equal(v.begin(), v.end(), v4.begin()) ); + + iterator_type it5 = v.erase(v.begin() + 2); + VERIFY( it5 == v.begin() + 2 ); + VERIFY( v.size() == N5 ); + VERIFY( std::equal(v.begin(), v.end(), v5.begin()) ); + + iterator_type it6 = v.erase(v.begin(), v.end()); + VERIFY( it6 == v.begin() ); + VERIFY( v.empty() ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc new file mode 100644 index 000000000..d76bed53c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/50529.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-09-26 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2011 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 <vector> +#include <testsuite_rvalref.h> + +// libstdc++/50529 +void test01() +{ + std::vector<__gnu_test::rvalstruct> v(10); + + for (auto it = v.begin(); it != v.end(); ++it) + v.erase(it, it); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc new file mode 100644 index 000000000..9e0c5597e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector<copycounter> a(40); + copycounter::copycount = 0; + + a.erase(a.begin() + 20); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 1); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin() + 10, a.end() - 10); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.begin() + 5); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 5, a.end()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.end()); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc new file mode 100644 index 000000000..dfd092dc5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/1.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 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 <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + vector<int> iv; + + try + { + iv.insert(iv.end(), iv.max_size() + 1, 1); + } + catch(std::length_error&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc new file mode 100644 index 000000000..969cb1c92 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/moveable.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005, 2006, 2007, 2008, 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 <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; + +// Test vector::push_back makes no unneeded copies. +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<copycounter> a; + copycounter c(1); + copycounter::copycount = 0; + for(int i = 0; i < 10; ++i) + a.push_back(c); + VERIFY(copycounter::copycount == 10); + + for(int i = 0; i < 100; ++i) + a.insert(a.begin() + i, c); + VERIFY(copycounter::copycount == 110); + + for(int i = 0; i < 1000; ++i) + a.insert(a.end(), c); + VERIFY(copycounter::copycount == 1110); +} + +// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies +// when it has to also reallocate the vector's internal buffer. +void +test02() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c), b(100, c); + copycounter::copycount = 0; + a.insert(a.begin(), b.begin(), b.begin() + 20); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), b.begin(), b.begin() + 50); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, b.begin(), b.end()); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies +// when it doesn't have to reallocate the vector's internal buffer. +void +test03() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c), b(100, c); + copycounter::copycount = 0; + a.reserve(1000); + VERIFY(copycounter::copycount == 0); + a.insert(a.begin(), b.begin(), b.begin() + 20); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), b.begin(), b.begin() + 50); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, b.begin(), b.end()); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, count, value) makes no unneeded copies +// when it has to also reallocate the vector's internal buffer. +void +test04() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c); + copycounter::copycount = 0; + a.insert(a.begin(), 20, c); + VERIFY(copycounter::copycount == 20); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70); + a.insert(a.begin() + 50, 100, c); + VERIFY(copycounter::copycount == 170); +} + +// Test vector::insert(iterator, count, value) makes no unneeded copies +// when it doesn't have to reallocate the vector's internal buffer. +void +test05() +{ + bool test __attribute__((unused)) = true; + + copycounter c(1); + std::vector<copycounter> a(10, c); + copycounter::copycount = 0; + a.reserve(1000); + a.insert(a.begin(), 20, c); + // NOTE : These values are each one higher than might be expected, as + // vector::insert(iterator, count, value) copies the value it is given + // when it doesn't reallocate the buffer. + VERIFY(copycounter::copycount == 20 + 1); + a.insert(a.end(), 50, c); + VERIFY(copycounter::copycount == 70 + 2); + a.insert(a.begin() + 50, 100, c); + VERIFY(copycounter::copycount == 170 + 3); +} + + + +int main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc new file mode 100644 index 000000000..f4fd4d8d6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2004, 2005, 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 <vector> +#include <testsuite_hooks.h> + +struct T { int i; }; + +int swap_calls; + +namespace std +{ + template<> + void + vector<T, allocator<T> >::swap(vector<T, allocator<T> >&) + { ++swap_calls; } +} + +// Should use vector specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::vector<T> A; + std::vector<T> B; + swap_calls = 0; + std::swap(A, B); + VERIFY(1 == swap_calls); +} + +// Should use vector specialization for swap. +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + vector<T> A; + vector<T> B; + swap_calls = 0; + swap(A, B); + VERIFY(1 == swap_calls); +} + +// See c++/13658 for background info. +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc new file mode 100644 index 000000000..e86f09416 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc @@ -0,0 +1,132 @@ +// 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.4.3 vector::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef vector<char, my_alloc> my_vector; + + 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); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1); + + my_vector vec01(alloc01); + size01 = vec01.size(); + my_vector vec02(alloc01); + size02 = vec02.size(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + + my_vector vec03(alloc01); + size01 = vec03.size(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + my_vector vec06(title02, title02 + N2, alloc01); + size02 = vec06.size(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + + my_vector vec07(title01, title01 + N1, alloc01); + size01 = vec07.size(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + my_vector vec10(title04, title04 + N4, alloc01); + size02 = vec10.size(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + + my_vector vec11(title04, title04 + N4, alloc01); + size01 = vec11.size(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + my_vector vec14(title03, title03 + N3, alloc01); + size02 = vec14.size(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc new file mode 100644 index 000000000..1809dd069 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc @@ -0,0 +1,161 @@ +// 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.4.3 vector::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef vector<char, my_alloc> my_vector; + + 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); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_vector vec01(alloc01); + size01 = vec01.size(); + personality01 = vec01.get_allocator().get_personality(); + my_vector vec02(alloc02); + size02 = vec02.size(); + personality02 = vec02.get_allocator().get_personality(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + VERIFY( vec01.get_allocator().get_personality() == personality02 ); + VERIFY( vec02.get_allocator().get_personality() == personality01 ); + + my_vector vec03(alloc02); + size01 = vec03.size(); + personality01 = vec03.get_allocator().get_personality(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + personality02 = vec04.get_allocator().get_personality(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + VERIFY( vec03.get_allocator().get_personality() == personality02 ); + VERIFY( vec04.get_allocator().get_personality() == personality01 ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + personality01 = vec05.get_allocator().get_personality(); + my_vector vec06(title02, title02 + N2, alloc02); + size02 = vec06.size(); + personality02 = vec06.get_allocator().get_personality(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + VERIFY( vec05.get_allocator().get_personality() == personality02 ); + VERIFY( vec06.get_allocator().get_personality() == personality01 ); + + my_vector vec07(title01, title01 + N1, alloc02); + size01 = vec07.size(); + personality01 = vec07.get_allocator().get_personality(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + personality02 = vec08.get_allocator().get_personality(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + VERIFY( vec07.get_allocator().get_personality() == personality02 ); + VERIFY( vec08.get_allocator().get_personality() == personality01 ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + personality01 = vec09.get_allocator().get_personality(); + my_vector vec10(title04, title04 + N4, alloc02); + size02 = vec10.size(); + personality02 = vec10.get_allocator().get_personality(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + VERIFY( vec09.get_allocator().get_personality() == personality02 ); + VERIFY( vec10.get_allocator().get_personality() == personality01 ); + + my_vector vec11(title04, title04 + N4, alloc02); + size01 = vec11.size(); + personality01 = vec11.get_allocator().get_personality(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + personality02 = vec12.get_allocator().get_personality(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + VERIFY( vec11.get_allocator().get_personality() == personality02 ); + VERIFY( vec12.get_allocator().get_personality() == personality01 ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + personality01 = vec13.get_allocator().get_personality(); + my_vector vec14(title03, title03 + N3, alloc02); + size02 = vec14.size(); + personality02 = vec14.get_allocator().get_personality(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); + VERIFY( vec13.get_allocator().get_personality() == personality02 ); + VERIFY( vec14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/profile/vector.cc b/libstdc++-v3/testsuite/23_containers/vector/profile/vector.cc new file mode 100644 index 000000000..1e9d01afe --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/profile/vector.cc @@ -0,0 +1,18 @@ +// Test vector: performance difference 25% (0.444s vs 0.539s) +// Advice: set tmp as 10000 + +#include <vector> + +using std::vector; + +int main() +{ + vector <int> tmp; + + for (int j=0; j<2000; j++) + // Insert more than default item + for (int i=0; i<10000; i++) { + tmp.push_back(i); + } +} + diff --git a/libstdc++-v3/testsuite/23_containers/vector/range_access.cc b/libstdc++-v3/testsuite/23_containers/vector/range_access.cc new file mode 100644 index 000000000..cbcbf6144 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/range_access.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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/>. + +// 24.6.5, range access [iterator.range] + +#include <vector> + +void +test01() +{ + std::vector<double> v{1.0, 2.0, 3.0}; + std::begin(v); + std::end(v); + + std::vector<bool> vb{true, false, true}; + std::begin(vb); + std::end(vb); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/citerators.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/citerators.cc new file mode 100644 index 000000000..eee16b04e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/citerators.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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 <vector> +#include <testsuite_containers.h> + +int main() +{ + typedef std::vector<int> test_type; + __gnu_test::citerator<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc new file mode 100644 index 000000000..f13dd0163 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc @@ -0,0 +1,35 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1150 } +// { dg-excess-errors "" } + +#include <vector> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + std::vector<A> v; + v.assign(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor.cc new file mode 100644 index 000000000..959e7a8ea --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor.cc @@ -0,0 +1,27 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 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/>. + +// { dg-do compile } + +#include <vector> + +void f() +{ + std::vector<int> v(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc new file mode 100644 index 000000000..471d4589b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc @@ -0,0 +1,29 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1080 } +// { dg-excess-errors "" } + +#include <vector> + +void f() +{ + std::vector<std::vector<int> > v(10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc new file mode 100644 index 000000000..8d1b72c63 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc @@ -0,0 +1,30 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1080 } +// { dg-excess-errors "" } + +#include <vector> +#include <utility> + +void f() +{ + std::vector<std::vector<std::pair<char, char> > > v('a', 'b'); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc new file mode 100644 index 000000000..2f10c5503 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc @@ -0,0 +1,35 @@ +// 2007-04-27 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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/>. + +// { dg-do compile } +// { dg-error "no matching" "" { target *-*-* } 1191 } +// { dg-excess-errors "" } + +#include <vector> + +struct A +{ + explicit A(int) { } +}; + +void f() +{ + std::vector<A> v; + v.insert(v.begin(), 10, 1); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/basic.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/basic.cc new file mode 100644 index 000000000..a31a05a06 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/basic.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-11-30 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <vector> +#include <exception/safety.h> + +void +value() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type; + typedef std::vector<value_type, allocator_type> test_type; + __gnu_test::basic_safety<test_type> test; +} + +// Container requirement testing, exceptional behavior +int main() +{ + value(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/generation_prohibited.cc new file mode 100644 index 000000000..acd2c211d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/generation_prohibited.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// Copyright (C) 2009, 2010 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 <vector> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_random value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::vector<value_type, allocator_type> test_type; + __gnu_test::generation_prohibited<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/propagation_consistent.cc new file mode 100644 index 000000000..7487ac372 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/exception/propagation_consistent.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2009-09-09 Benjamin Kosnik <benjamin@redhat.com> + +// 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 <vector> +#include <exception/safety.h> + +// Container requirement testing, exceptional behavior +int main() +{ + typedef __gnu_cxx::throw_value_limit value_type; + typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type; + typedef std::vector<value_type, allocator_type> test_type; + __gnu_test::propagation_consistent<test_type> test; + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..5310ec4f2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/1.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <vector> + +// { dg-do compile } + +template class std::vector<int>; diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/1_c++0x.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/1_c++0x.cc new file mode 100644 index 000000000..2e5787702 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/1_c++0x.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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/>. + +// This file tests explicit instantiation of library containers + +#include <vector> + +template class std::vector<int>; diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..4ec749b73 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/2.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2004, 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/>. + + +// This file tests explicit instantiation of library containers + +#include <vector> +#include <testsuite_api.h> + +// { dg-do compile } + +// N.B. In C++0x mode we cannot instantiate with T == NonDefaultConstructible +// because of 23.4.1.1.4 +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +template class std::vector<__gnu_test::NonDefaultConstructible>; +#endif diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/3.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/3.cc new file mode 100644 index 000000000..0256b086a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/3.cc @@ -0,0 +1,26 @@ +// 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/>. + + +// This file tests explicit instantiation of library containers + +#include <vector> + +// { dg-do compile } + +// libstdc++/21770 +template class std::vector<int, std::allocator<char> >; diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..9305e3c87 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/explicit_instantiation/4.cc @@ -0,0 +1,29 @@ +// 2010-05-20 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 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/>. + +// This file tests explicit instantiation of library containers + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +// { dg-do compile } + +// libstdc++/41792 +template class std::vector<__gnu_test::OverloadedAddress>; diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/partial_specialization/1.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/partial_specialization/1.cc new file mode 100644 index 000000000..00db9cecb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/partial_specialization/1.cc @@ -0,0 +1,33 @@ +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 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/>. + + +// This file tests user specialization of library containers + +#include <vector> +#include <testsuite_hooks.h> + +// { dg-do compile } + +struct user_type {}; + +namespace std +{ + template<typename Allocator> + class vector<user_type, Allocator> {}; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/requirements/typedefs.cc b/libstdc++-v3/testsuite/23_containers/vector/requirements/typedefs.cc new file mode 100644 index 000000000..24897ff3a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/requirements/typedefs.cc @@ -0,0 +1,25 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// 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 <testsuite_containers.h> +#include <vector> + +// Check container for required typedefs. +__gnu_test::types<std::vector<int> > t; diff --git a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc new file mode 100644 index 000000000..dd2f8f646 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc @@ -0,0 +1,41 @@ +// 2005-12-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009, 2010 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/>. + +// { dg-do compile } + +#include <vector> +#include <testsuite_greedy_ops.h> + +int main() +{ + std::vector<greedy_ops::X> v(5); + const std::vector<greedy_ops::X> w(1); + + v[0]; + w[0]; + v.size(); + v.capacity(); + v.resize(1); + v.insert(v.begin(), greedy_ops::X()); + v.insert(v.begin(), 1, greedy_ops::X()); + v.insert(v.begin(), w.begin(), w.end()); + v = w; + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/types/23767.cc b/libstdc++-v3/testsuite/23_containers/vector/types/23767.cc new file mode 100644 index 000000000..6e178d728 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/types/23767.cc @@ -0,0 +1,43 @@ +// 2005-09-12 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/>. +// + +// { dg-do compile } + +#include <vector> + +struct T +{ + typedef std::vector<int> Vector; + typedef Vector::iterator iterator; + typedef Vector::const_iterator const_iterator; + + int t(iterator f) { return *f; } + int t(const_iterator f) const { return *f; } +}; + +// libstdc++/23767 +void f() +{ + std::vector<int> v; + T t; + T::const_iterator i = v.begin(); + + t.t(i); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc b/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc new file mode 100644 index 000000000..7441cf89d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/zero_sized_allocations.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2007, 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 <vector> +#include <cstdlib> +#include <testsuite_hooks.h> + +unsigned int zero_sized_news = 0; + +void *operator new(size_t size) throw (std::bad_alloc) +{ + /* malloc(0) is unpredictable; avoid it. */ + if (size == 0) + { + size = 1; + ++zero_sized_news; + } + + void *p = std::malloc(size); + + if (p == 0) + throw std::bad_alloc(); + + return p; +} + +void operator delete(void *ptr) throw() +{ + if (ptr != 0) + std::free(ptr); +} + +// http://gcc.gnu.org/ml/libstdc++/2007-09/msg00006.html +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<std::vector<int> > *v; + VERIFY( zero_sized_news == 0 ); + + v = new std::vector<std::vector<int> >; + VERIFY( zero_sized_news == 0 ); + + v->resize(10); + delete(v); + VERIFY( zero_sized_news == 0 ); +} + +int main() +{ + test01(); + return 0; +} |