From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../23_containers/set/modifiers/swap/1.cc | 65 ++++++++ .../23_containers/set/modifiers/swap/2.cc | 137 +++++++++++++++++ .../23_containers/set/modifiers/swap/3.cc | 166 +++++++++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc create mode 100644 libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc (limited to 'libstdc++-v3/testsuite/23_containers/set/modifiers/swap') 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 +// . + +#include +#include + +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::swap(set&) + { ++swap_calls; } +} + +// Should use set specialization for swap. +void test01() +{ + bool test __attribute__((unused)) = true; + std::set A; + std::set 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 A; + set 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 + +// 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 +// . + +// 23.3.3 set::swap + +#include +#include +#include + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator my_alloc; + typedef set, 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 set01_ref(title01, title01 + N1); + const set set02_ref(title02, title02 + N2); + const set set03_ref(title03, title03 + N3); + const set set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1); + + my_set set01(less(), alloc01); + size01 = set01.size(); + my_set set02(less(), 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(), alloc01); + size01 = set03.size(); + my_set set04(title02, title02 + N2, less(), 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(), alloc01); + size01 = set05.size(); + my_set set06(title02, title02 + N2, less(), 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(), alloc01); + size01 = set07.size(); + my_set set08(title03, title03 + N3, less(), 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(), alloc01); + size01 = set09.size(); + my_set set10(title04, title04 + N4, less(), 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(), alloc01); + size01 = set11.size(); + my_set set12(title01, title01 + N1, less(), 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(), alloc01); + size01 = set13.size(); + my_set set14(title03, title03 + N3, less(), 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 + +// 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 +// . + +// 23.3.3 set::swap + +#include +#include +#include + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator my_alloc; + typedef set, 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 set01_ref(title01, title01 + N1); + const set set02_ref(title02, title02 + N2); + const set set03_ref(title03, title03 + N3); + const set set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_set set01(less(), alloc01); + size01 = set01.size(); + personality01 = set01.get_allocator().get_personality(); + my_set set02(less(), 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(), alloc02); + size01 = set03.size(); + personality01 = set03.get_allocator().get_personality(); + my_set set04(title02, title02 + N2, less(), 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(), alloc01); + size01 = set05.size(); + personality01 = set05.get_allocator().get_personality(); + my_set set06(title02, title02 + N2, less(), 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(), alloc02); + size01 = set07.size(); + personality01 = set07.get_allocator().get_personality(); + my_set set08(title03, title03 + N3, less(), 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(), alloc01); + size01 = set09.size(); + personality01 = set09.get_allocator().get_personality(); + my_set set10(title04, title04 + N4, less(), 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(), alloc02); + size01 = set11.size(); + personality01 = set11.get_allocator().get_personality(); + my_set set12(title01, title01 + N1, less(), 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(), alloc01); + size01 = set13.size(); + personality01 = set13.get_allocator().get_personality(); + my_set set14(title03, title03 + N3, less(), 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; +} -- cgit v1.2.3