From 18dddd091cb14ff948375e11e1bb5943c16c7815 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 1 Sep 2009 10:19:11 +0000 Subject: 2009-09-01 Chris Jefferson Paolo Carlini * testsuite/util/testsuite_rvalref.h: Remove obsolete macro using _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING. * testsuite/20_util/specialized_algorithms/uninitialized_copy_n/ move_iterators/1.cc: Adjust, do not define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING. * testsuite/20_util/specialized_algorithms/uninitialized_copy/ move_iterators/1.cc: Likewise. * testsuite/25_algorithms/copy_n/move_iterators/1.cc: Likewise. * testsuite/25_algorithms/move/1.cc: Likewise. * testsuite/25_algorithms/move_backward/1.cc: Likewise. * testsuite/25_algorithms/copy_backward/move_iterators/1.cc: Likewise. * testsuite/25_algorithms/copy/move_iterators/1.cc: Likewise. * testsuite/25_algorithms/heap/moveable.cc: Likewise. * testsuite/25_algorithms/partial_sort/moveable.cc: Likewise; add test for predicated test. * testsuite/25_algorithms/sort/moveable.cc: Likewise. * testsuite/25_algorithms/nth_element/moveable.cc: Add test for predicated version. * testsuite/25_algorithms/unique/moveable.cc: Likewise. * testsuite/25_algorithms/inplace_merge/1.cc (S::operator<): Fix, enable test2 and test3. * testsuite/util/testsuite_iterators.h (operator=): Fix invalid moving bug in C++0x mode. * testsuite/25_algorithms/random_shuffle/moveable.cc: New. * testsuite/25_algorithms/prev_permutation/moveable.cc: Likewise. * testsuite/25_algorithms/next_permutation/moveable.cc: Likewise. * testsuite/25_algorithms/heap/moveable2.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151264 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 34 +++++ .../uninitialized_copy/move_iterators/1.cc | 1 - .../uninitialized_copy_n/move_iterators/1.cc | 1 - .../25_algorithms/copy/move_iterators/1.cc | 1 - .../copy_backward/move_iterators/1.cc | 1 - .../25_algorithms/copy_n/move_iterators/1.cc | 1 - .../testsuite/25_algorithms/heap/moveable.cc | 11 +- .../testsuite/25_algorithms/heap/moveable2.cc | 157 +++++++++++++++++++++ .../testsuite/25_algorithms/inplace_merge/1.cc | 20 ++- libstdc++-v3/testsuite/25_algorithms/move/1.cc | 1 - .../testsuite/25_algorithms/move_backward/1.cc | 1 - .../25_algorithms/next_permutation/moveable.cc | 121 ++++++++++++++++ .../25_algorithms/nth_element/moveable.cc | 41 +++++- .../25_algorithms/partial_sort/moveable.cc | 35 ++++- .../25_algorithms/prev_permutation/moveable.cc | 121 ++++++++++++++++ .../25_algorithms/random_shuffle/moveable.cc | 85 +++++++++++ .../testsuite/25_algorithms/sort/moveable.cc | 44 ++++-- .../testsuite/25_algorithms/unique/moveable.cc | 43 +++++- libstdc++-v3/testsuite/util/testsuite_iterators.h | 12 +- libstdc++-v3/testsuite/util/testsuite_rvalref.h | 10 -- 20 files changed, 676 insertions(+), 65 deletions(-) create mode 100644 libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fb0d38ddeaf..5d9031ed817 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,37 @@ +2009-09-01 Chris Jefferson + Paolo Carlini + + * testsuite/util/testsuite_rvalref.h: Remove obsolete macro using + _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING. + * testsuite/20_util/specialized_algorithms/uninitialized_copy_n/ + move_iterators/1.cc: Adjust, do not define + _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING. + * testsuite/20_util/specialized_algorithms/uninitialized_copy/ + move_iterators/1.cc: Likewise. + * testsuite/25_algorithms/copy_n/move_iterators/1.cc: Likewise. + * testsuite/25_algorithms/move/1.cc: Likewise. + * testsuite/25_algorithms/move_backward/1.cc: Likewise. + * testsuite/25_algorithms/copy_backward/move_iterators/1.cc: Likewise. + * testsuite/25_algorithms/copy/move_iterators/1.cc: Likewise. + * testsuite/25_algorithms/heap/moveable.cc: Likewise. + * testsuite/25_algorithms/partial_sort/moveable.cc: Likewise; add + test for predicated test. + * testsuite/25_algorithms/sort/moveable.cc: Likewise. + * testsuite/25_algorithms/nth_element/moveable.cc: Add test + for predicated version. + * testsuite/25_algorithms/unique/moveable.cc: Likewise. + + * testsuite/25_algorithms/inplace_merge/1.cc (S::operator<): Fix, + enable test2 and test3. + + * testsuite/util/testsuite_iterators.h (operator=): Fix invalid + moving bug in C++0x mode. + + * testsuite/25_algorithms/random_shuffle/moveable.cc: New. + * testsuite/25_algorithms/prev_permutation/moveable.cc: Likewise. + * testsuite/25_algorithms/next_permutation/moveable.cc: Likewise. + * testsuite/25_algorithms/heap/moveable2.cc: Likewise. + 2009-08-31 Uros Bizjak Kaz Kojima diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc index a869ea8a87a..5d1ba942d54 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc @@ -18,7 +18,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc index f54f2f5ada3..fc11a74eba9 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc @@ -20,7 +20,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc index c97a486e36e..e07c4920cd2 100644 --- a/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc @@ -18,7 +18,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/1.cc index 0b8b70b9480..aaf50064f16 100644 --- a/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/1.cc @@ -18,7 +18,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_n/move_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy_n/move_iterators/1.cc index fedb03a868e..6c22ba672ac 100644 --- a/libstdc++-v3/testsuite/25_algorithms/copy_n/move_iterators/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/move_iterators/1.cc @@ -20,7 +20,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc index 10456c91aad..0a696591682 100644 --- a/libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc @@ -22,7 +22,6 @@ // 25.3.6 Heap operations [lib.alg.heap.operations] #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include @@ -40,11 +39,11 @@ using __gnu_test::rvalstruct; typedef test_container container; typedef test_container container_ref; -bool test __attribute__((unused)) = true; - void check_make(int* array, int length) { + bool test __attribute__((unused)) = true; + rvalstruct makeheap[9]; int makeheap_ref[9]; std::copy(array, array + length, makeheap); @@ -63,6 +62,8 @@ check_make(int* array, int length) void check_pop(int* array, int length) { + bool test __attribute__((unused)) = true; + rvalstruct popheap[9]; int popheap_ref[9]; std::copy(array, array + length, popheap); @@ -81,6 +82,8 @@ check_pop(int* array, int length) void check_sort(int* array, int length) { + bool test __attribute__((unused)) = true; + rvalstruct sortheap[9]; int sortheap_ref[9]; std::copy(array, array + length, sortheap); @@ -99,6 +102,8 @@ check_sort(int* array, int length) void check_push(int* array, int pushval, int length) { + bool test __attribute__((unused)) = true; + rvalstruct pushheap[10]; int pushheap_ref[10]; std::copy(array, array + length, pushheap); diff --git a/libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc b/libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc new file mode 100644 index 00000000000..86eefbee63c --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc @@ -0,0 +1,157 @@ +// { 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 Pred the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++0x -DITERATIONS=5" { target simulator } } + +// 25.3.6 Heap operations [lib.alg.heap.operations] + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include +#include +#include +#include + +#ifndef ITERATIONS +#define ITERATIONS 9 +#endif + +using __gnu_test::test_container; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container container; +typedef test_container container_ref; + +bool are_ordered(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +bool are_ordered_int(const int& lhs, const int& rhs) +{ return lhs < rhs; } + +void +check_make(int* array, int length) +{ + bool test __attribute__((unused)) = true; + + rvalstruct makeheap[9]; + int makeheap_ref[9]; + std::copy(array, array + length, makeheap); + std::copy(array, array + length, makeheap_ref); + container makecon(makeheap, makeheap + length); + container_ref makecon_ref(makeheap_ref, makeheap_ref + length); + std::make_heap(makecon.begin(), makecon.end(), are_ordered); + std::make_heap(makecon_ref.begin(), makecon_ref.end(), are_ordered_int); + for (int z = 0; z < length; ++z) + VERIFY( makeheap[z] == makeheap_ref[z] ); + VERIFY( std::__is_heap(makecon.begin(), makecon.end(), are_ordered) ); + for (int z = 0; z < length; ++z) + VERIFY( makeheap[z].valid ); +} + +void +check_pop(int* array, int length) +{ + bool test __attribute__((unused)) = true; + + rvalstruct popheap[9]; + int popheap_ref[9]; + std::copy(array, array + length, popheap); + std::copy(array, array + length, popheap_ref); + container popcon(popheap, popheap + length); + container_ref popcon_ref(popheap_ref, popheap_ref + length); + std::pop_heap(popcon.begin(), popcon.end(), are_ordered); + std::pop_heap(popcon_ref.begin(), popcon_ref.end(), are_ordered_int); + for (int z = 0; z < length; ++z) + VERIFY( popheap[z] == popheap_ref[z] ); + VERIFY( (std::__is_heap(popheap, popheap + length - 1), are_ordered) ); + for (int z = 0; z < length; ++z) + VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid ); +} + +void +check_sort(int* array, int length) +{ + bool test __attribute__((unused)) = true; + + rvalstruct sortheap[9]; + int sortheap_ref[9]; + std::copy(array, array + length, sortheap); + std::copy(array, array + length, sortheap_ref); + container sortcon(sortheap, sortheap + length); + container_ref sortcon_ref(sortheap_ref, sortheap_ref + length); + std::sort_heap(sortcon.begin(), sortcon.end(), are_ordered); + std::sort_heap(sortcon_ref.begin(), sortcon_ref.end(), are_ordered_int); + for (int z = 0; z < length; ++z) + VERIFY( sortheap[z] == sortheap_ref[z] ); + for (int z = 0; z < length - 1; ++z) + VERIFY( sortheap[z].val <= sortheap[z + 1].val && sortheap[z].valid ); + VERIFY( sortheap[length - 1].valid ); +} + +void +check_push(int* array, int pushval, int length) +{ + bool test __attribute__((unused)) = true; + + rvalstruct pushheap[10]; + int pushheap_ref[10]; + std::copy(array, array + length, pushheap); + std::copy(array, array + length, pushheap_ref); + pushheap[length] = pushval; + pushheap_ref[length] = pushval; + container pushcon(pushheap, pushheap + length + 1); + container_ref pushcon_ref(pushheap_ref, pushheap_ref + length + 1); + std::push_heap(pushcon.begin(), pushcon.end(), are_ordered); + std::push_heap(pushcon_ref.begin(), pushcon_ref.end(), are_ordered_int); + for (int z = 0; z < length + 1; ++z) + VERIFY( pushheap[z] == pushheap_ref[z] ); + VERIFY( std::__is_heap(pushheap, pushheap + length + 1) ); + for (int z = 0; z < length + 1; ++z) + VERIFY( pushheap[z].valid ); +} + +void +test01() +{ + int array[9]; + for (int i = 1; i < ITERATIONS; ++i) + { + for(int z = 0; z < i; ++z) + array[z] = z; + while (std::next_permutation(array, array + i)) + { + check_make(array, i); + if (std::__is_heap(array, array + i, are_ordered_int)) + { + check_pop(array, i); + check_sort(array, i); + for (int pushval = -1; pushval <= i; ++pushval) + check_push(array, pushval, i); + } + } + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/1.cc b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/1.cc index d3195ab7b64..d4da753b6dd 100644 --- a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/1.cc @@ -27,11 +27,10 @@ using std::inplace_merge; typedef test_container container; - void test1() { - int array[]={1}; + int array[] = { 1 }; container con1(array, array); inplace_merge(con1.begin(), con1.end(), con1.end()); container con2(array, array + 1); @@ -42,11 +41,13 @@ test1() void test2() { - int array[]={0,2,4,1,3,5}; + bool test __attribute__((unused)) = true; + + int array[] = { 0, 2, 4, 1, 3, 5 }; container con(array, array + 6); inplace_merge(con.begin(), con.it(3), con.end()); - VERIFY(array[0] == 0 && array[1] == 1 && array[2] == 2 && - array[3] == 3 && array[4] == 4 && array[5] == 5); + VERIFY( array[0] == 0 && array[1] == 1 && array[2] == 2 + && array[3] == 3 && array[4] == 4 && array[5] == 5 ); } struct S @@ -57,12 +58,14 @@ struct S S() { } bool operator<(const S& _s) const - { return _s.a < a; } + { return a < _s.a; } }; void test3() { + bool test __attribute__((unused)) = true; + S s[4]; s[0].a = 0; s[1].a = 1; @@ -73,11 +76,14 @@ test3() s[2].b = 1; s[3].b = 1; inplace_merge(s, s + 2, s + 4); - VERIFY(s[0].b == 0 && s[1].b == 1 && s[2].b == 0 && s[3].b == 1); + VERIFY( s[0].b == 0 && s[1].b == 1 && s[2].b == 0 && s[3].b == 1 ); } int main() { test1(); + test2(); + test3(); + return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/move/1.cc b/libstdc++-v3/testsuite/25_algorithms/move/1.cc index 085fbe0c8bf..b577cfa5d6d 100644 --- a/libstdc++-v3/testsuite/25_algorithms/move/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/move/1.cc @@ -18,7 +18,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc index 7d46ab3ab6a..436ccb03124 100644 --- a/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc @@ -18,7 +18,6 @@ // . #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include diff --git a/libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc new file mode 100644 index 00000000000..d754f6b3c28 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc @@ -0,0 +1,121 @@ +// { 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 +// . + +// 25.3.9 [lib.alg.permutation.generators] + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::next_permutation; + +typedef test_container Container; + +void +test1() +{ + bool test __attribute__((unused)) = true; + + // Note: The standard is unclear on what should happen in this case. + // This seems the only really sensible behaviour, and what is done. + rvalstruct array[] = {0}; + Container con(array, array); + VERIFY( !next_permutation(con.begin(), con.end()) ); +} + +void +test2() +{ + bool test __attribute__((unused)) = true; + + rvalstruct array[] = {0}; + Container con(array, array + 1); + VERIFY( !next_permutation(con.begin(), con.end()) ); +} + +void +test3() +{ + bool test __attribute__((unused)) = true; + + rvalstruct array[] = {0, 3}; + Container con(array, array + 2); + VERIFY( next_permutation(con.begin(), con.end()) ); + VERIFY( array[0] == 3 && array[1] == 0 ); + VERIFY( !next_permutation(con.begin(), con.end()) ); + VERIFY( array[0] == 0 && array[1] == 3 ); +} + +void +test4() +{ + bool test __attribute__((unused)) = true; + + int array[6] = {0, 1, 2, 3, 4, 5}; + for(int i = 0 ; i < 719; ++i) + { + rvalstruct temp_array[6]; + std::copy(array, array + 6, temp_array); + Container con(temp_array, temp_array + 6); + VERIFY( next_permutation(array, array + 6) ); + VERIFY( std::lexicographical_compare(temp_array, temp_array + 6, + array, array + 6) ); + } + VERIFY( !next_permutation(array,array + 6) ); + for(int i = 0; i < 6; ++i) + VERIFY( array[i] == i ); +} + +bool +are_ordered(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +void +test5() +{ + bool test __attribute__((unused)) = true; + + int array[6] = {0, 1, 2, 3, 4, 5}; + for(int i = 0 ; i < 719; ++i) + { + rvalstruct temp_array[6]; + std::copy(array, array + 6, temp_array); + Container con(temp_array, temp_array + 6); + VERIFY( next_permutation(array, array + 6, are_ordered) ); + VERIFY( std::lexicographical_compare(temp_array, temp_array + 6, + array, array + 6, are_ordered) ); + } + VERIFY( !next_permutation(array,array + 6, are_ordered) ); + for(int i = 0; i < 6; ++i) + VERIFY( array[i] == i ); +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc index 005f6ec7cbc..93a514fa8bc 100644 --- a/libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc. +// 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 @@ -36,33 +36,59 @@ typedef test_container Container; void test1() { + bool test __attribute__((unused)) = true; + int intarray[] = {6, 5, 4, 3, 2, 1, 0}; rvalstruct array[7]; std::copy(intarray, intarray + 7, array); Container con(array, array + 7); nth_element(con.begin(), con.it(3), con.end()); for(int i = 0; i < 3; ++i) - VERIFY(array[i].val < 3); + VERIFY( array[i].val < 3 ); for(int i = 4; i < 7; ++i) - VERIFY(array[i].val > 3); + VERIFY( array[i].val > 3 ); for(int i = 0; i < 7; ++i) - VERIFY(array[i].valid); + VERIFY( array[i].valid ); } void test2() { + bool test __attribute__((unused)) = true; + int intarray[] = {0, 6, 1, 5, 2, 4, 3}; rvalstruct array[7]; std::copy(intarray, intarray + 7, array); Container con(array,array + 7); nth_element(con.begin(), con.it(3), con.end()); for(int i = 0; i < 3; ++i) - VERIFY(array[i].val < 3); + VERIFY( array[i].val < 3 ); + for(int i = 4; i < 7; ++i) + VERIFY( array[i].val > 3 ); + for(int i = 0; i < 7; ++i) + VERIFY( array[i].valid ); +} + +bool +are_less(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +void +test3() +{ + bool test __attribute__((unused)) = true; + + int intarray[] = {0, 6, 1, 5, 2, 4, 3}; + rvalstruct array[7]; + std::copy(intarray, intarray + 7, array); + Container con(array,array + 7); + nth_element(con.begin(), con.it(3), con.end(), are_less); + for(int i = 0; i < 3; ++i) + VERIFY( array[i].val < 3 ); for(int i = 4; i < 7; ++i) - VERIFY(array[i].val > 3); + VERIFY( array[i].val > 3 ); for(int i = 0; i < 7; ++i) - VERIFY(array[i].valid); + VERIFY( array[i].valid ); } int @@ -70,5 +96,6 @@ main() { test1(); test2(); + test3(); return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort/moveable.cc index 8328bd5d6cd..fcad384dcdf 100644 --- a/libstdc++-v3/testsuite/25_algorithms/partial_sort/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/partial_sort/moveable.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc. +// 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 @@ -20,7 +20,6 @@ // 25.3.1.3 [lib.partial.sort] #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include @@ -37,27 +36,49 @@ typedef test_container Container; void test1() { + bool test __attribute__((unused)) = true; + int intarray[] = {6, 5, 4, 3, 2, 1, 0}; rvalstruct array[7]; std::copy(intarray, intarray + 7, array); Container con(array, array + 7); partial_sort(con.begin(), con.it(3), con.end()); - VERIFY(array[0].val == 0 && array[1].val == 1 && array[2].val == 2); + VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 ); for(int i = 0; i < 7; ++i) - VERIFY(array[i].valid); + VERIFY( array[i].valid ); } void test2() { + bool test __attribute__((unused)) = true; + int intarray[] = {0, 6, 1, 5, 2, 4, 3}; rvalstruct array[7]; std::copy(intarray, intarray + 7, array); Container con(array,array + 7); partial_sort(con.begin(), con.it(3), con.end()); - VERIFY(array[0].val == 0 && array[1].val == 1 && array[2].val == 2); + VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 ); + for(int i = 0; i < 7; ++i) + VERIFY( array[i].valid ); +} + +bool are_less(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +void +test3() +{ + bool test __attribute__((unused)) = true; + + int intarray[] = {0, 6, 1, 5, 2, 4, 3}; + rvalstruct array[7]; + std::copy(intarray, intarray + 7, array); + Container con(array,array + 7); + partial_sort(con.begin(), con.it(3), con.end(), are_less); + VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 ); for(int i = 0; i < 7; ++i) - VERIFY(array[i].valid); + VERIFY( array[i].valid ); } int @@ -65,4 +86,6 @@ main() { test1(); test2(); + test3(); + return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc new file mode 100644 index 00000000000..796c5df1b3c --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc @@ -0,0 +1,121 @@ +// { 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 +// . + +// 25.3.9 [lib.alg.permutation.generators] + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::prev_permutation; + +typedef test_container Container; + +void +test1() +{ + bool test __attribute__((unused)) = true; + + // Note: The standard is unclear on what should happen in this case. + // This seems the only really sensible behaviour, and what is done. + rvalstruct array[] = {0}; + Container con(array, array); + VERIFY( !prev_permutation(con.begin(), con.end()) ); +} + +void +test2() +{ + bool test __attribute__((unused)) = true; + + rvalstruct array[] = {0}; + Container con(array, array + 1); + VERIFY( !prev_permutation(con.begin(), con.end()) ); +} + +void +test3() +{ + bool test __attribute__((unused)) = true; + + rvalstruct array[] = {3, 0}; + Container con(array, array + 2); + VERIFY( prev_permutation(con.begin(), con.end()) ); + VERIFY( array[0] == 0 && array[1] == 3 ); + VERIFY( !prev_permutation(con.begin(), con.end()) ); + VERIFY( array[0] == 3 && array[1] == 0 ); +} + +void +test4() +{ + bool test __attribute__((unused)) = true; + + int array[6] = {5, 4, 3, 2, 1, 0}; + for(int i = 0 ; i < 719; ++i) + { + rvalstruct temp_array[6]; + std::copy(array, array + 6, temp_array); + Container con(temp_array, temp_array + 6); + VERIFY( prev_permutation(array, array + 6) ); + VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6, + array, array + 6) ); + } + VERIFY( !prev_permutation(array,array + 6)) ; + for(int i = 0; i < 6; ++i) + VERIFY( array[i] == (5 - i) ); +} + +bool +are_ordered(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +void +test5() +{ + bool test __attribute__((unused)) = true; + + int array[6] = {5, 4, 3, 2, 1, 0}; + for(int i = 0 ; i < 719; ++i) + { + rvalstruct temp_array[6]; + std::copy(array, array + 6, temp_array); + Container con(temp_array, temp_array + 6); + VERIFY( prev_permutation(array, array + 6, are_ordered) ); + VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6, + array, array + 6, are_ordered) ); + } + VERIFY( !prev_permutation(array,array + 6, are_ordered) ); + for(int i = 0; i < 6; ++i) + VERIFY( array[i] == (5 - i) ); +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc new file mode 100644 index 00000000000..6a44bb8c8c4 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.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 +// . + +// 25.2.11 random_shuffle() + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container Container; + +const int N = 200000; +int A[N]; + +void fill_ascending() +{ + for (int i = 0; i < N; ++i) + A[i] = i; +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + + fill_ascending(); + rvalstruct rv[N]; + std::copy(A, A + N, rv); + Container con(rv, rv + N); + std::random_shuffle(con.begin(), con.end()); + + // The chance that random_shuffle leaves the order as is by coincidence + // is negligible, so we expect it to be permuted + VERIFY( !std::equal(rv, rv + N, A) ); + + std::sort(con.begin(), con.end()); + VERIFY( std::equal(rv, rv + N, A) ); +} + +int random_generator(int) +{ return 0; } + +void +test02() +{ + bool test __attribute__((unused)) = true; + + fill_ascending(); + rvalstruct rv[10] = {1,2,3,4,5,6,7,8,9,10}; + int result[10] = {10,1,2,3,4,5,6,7,8,9}; + Container con(rv, rv + 10); + std::random_shuffle(con.begin(), con.end(), random_generator); + // The above answer was generated by hand. It is not required by the standard, + // but is produced by the current algorithm. + VERIFY( std::equal(rv, rv + 10, result) ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc index 61f4473530f..6972d16681d 100644 --- a/libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc @@ -1,7 +1,6 @@ -// { dg-require-rvalref "" } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc. +// 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 @@ -21,15 +20,12 @@ // 25.3.1 algorithms, sort() #undef _GLIBCXX_CONCEPT_CHECKS -#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING #include #include #include #include -bool test __attribute__((unused)) = true; - using __gnu_test::test_container; using __gnu_test::random_access_iterator_wrapper; using __gnu_test::rvalstruct; @@ -37,27 +33,47 @@ using std::partial_sort; typedef test_container Container; - const int A[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, - 17, 8, 18, 9, 19}; + 17, 8, 18, 9, 19}; const int N = sizeof(A) / sizeof(int); // 25.3.1.1 sort() void test01() { - rvalstruct s1[N]; - std::copy(A, A + N, s1); - Container con(s1, s1 + N); - std::sort(con.begin(), con.end()); - VERIFY(s1[0].valid); - for(int i = 1; i < N; ++i) - VERIFY(s1[i].val>s1[i-1].val && s1[i].valid); + bool test __attribute__((unused)) = true; + + rvalstruct s1[N]; + std::copy(A, A + N, s1); + Container con(s1, s1 + N); + std::sort(con.begin(), con.end()); + VERIFY( s1[0].valid ); + for(int i = 1; i < N; ++i) + VERIFY( s1[i].val>s1[i-1].val && s1[i].valid ); +} + +bool order(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +// 25.3.1.1 sort() +void +test02() +{ + bool test __attribute__((unused)) = true; + + rvalstruct s1[N]; + std::copy(A, A + N, s1); + Container con(s1, s1 + N); + std::sort(con.begin(), con.end(), order); + VERIFY( s1[0].valid ); + for(int i = 1; i < N; ++i) + VERIFY( s1[i].val>s1[i-1].val && s1[i].valid ); } int main() { test01(); + test02(); return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc index 6f072d50116..b5bf16dbb1f 100644 --- a/libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc +++ b/libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc. +// 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 @@ -54,19 +54,52 @@ void test01() Container con(T1, T1 + N); - VERIFY(std::unique(con.begin(), con.end()).ptr - T1 == 12); + VERIFY( std::unique(con.begin(), con.end()).ptr - T1 == 12 ); for(int i = 0; i < 12; ++i) - VERIFY(T1[i].val == A1[i]); + VERIFY( T1[i].val == A1[i] ); Container con2(T2, T2 + N); - VERIFY(std::unique(con2.begin(), con2.end()).ptr - T2 == 8); + VERIFY( std::unique(con2.begin(), con2.end()).ptr - T2 == 8 ); for(int i = 0; i < 8; ++i) - VERIFY(T2[i].val == B1[i]); + VERIFY( T2[i].val == B1[i] ); } +bool are_equal(const rvalstruct& rhs, const rvalstruct& lhs) +{ return rhs == lhs; } + +void test02() +{ + bool test __attribute__((unused)) = true; + + int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4}; + int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9}; + + const int N = sizeof(intarray1) / sizeof(int); + + rvalstruct T1[N]; + rvalstruct T2[N]; + + std::copy(intarray1,intarray1 + N, T1); + std::copy(intarray2,intarray2 + N, T2); + + const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4}; + const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9}; + + Container con(T1, T1 + N); + + VERIFY( std::unique(con.begin(), con.end(), are_equal).ptr - T1 == 12 ); + for(int i = 0; i < 12; ++i) + VERIFY( T1[i].val == A1[i] ); + + Container con2(T2, T2 + N); + VERIFY( std::unique(con2.begin(), con2.end(), are_equal).ptr - T2 == 8 ); + for(int i = 0; i < 8; ++i) + VERIFY( T2[i].val == B1[i] ); +} int main() { test01(); + test02(); return 0; } diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index 1b14c893c7d..14a725fcbec 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -88,23 +88,23 @@ namespace __gnu_test ptr(ptr_in), SharedInfo(SharedInfo_in) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ template void - operator=(const U& new_val) + operator=(U&& new_val) { ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0); SharedInfo->writtento[ptr - SharedInfo->first] = 1; - *ptr = new_val; + *ptr = std::forward(new_val); } - -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#else template void - operator=(U&& new_val) + operator=(const U& new_val) { ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0); SharedInfo->writtento[ptr - SharedInfo->first] = 1; - *ptr = std::move(new_val); + *ptr = new_val; } #endif }; diff --git a/libstdc++-v3/testsuite/util/testsuite_rvalref.h b/libstdc++-v3/testsuite/util/testsuite_rvalref.h index 4e2f59c48f4..b44d6ddd12d 100644 --- a/libstdc++-v3/testsuite/util/testsuite_rvalref.h +++ b/libstdc++-v3/testsuite/util/testsuite_rvalref.h @@ -35,19 +35,9 @@ namespace __gnu_test bool operator=(const rvalstruct&); -// Normally we don't define a copy constructor, as any use of it would -// show an inefficency. In some cases we know it will be aliased away -// by the compiler, but it still insists it is defined, so we provide -// a way of making it public but not giving a body, so any usage would -// instead fail at link-time. -#ifdef _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING - public: - rvalstruct(const rvalstruct&); -#else rvalstruct(const rvalstruct&); public: -#endif int val; bool valid; -- cgit v1.2.1