diff options
author | François Dumont <francois.cppdevs@free.fr> | 2010-12-08 02:23:41 +0100 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2010-12-08 01:23:41 +0000 |
commit | f38716953daca9ee3fc954384678241e617a18bf (patch) | |
tree | ac8a43e1c1fd71f771edded23b172af763d98a8c | |
parent | 2b843fad50847f9a9fee935282022500657578fc (diff) | |
download | gcc-f38716953daca9ee3fc954384678241e617a18bf.zip gcc-f38716953daca9ee3fc954384678241e617a18bf.tar.gz gcc-f38716953daca9ee3fc954384678241e617a18bf.tar.bz2 |
stl_iterator.h: Add move_iterator operators overloads to make it robust to template abuses.
2010-12-07 François Dumont <francois.cppdevs@free.fr>
* include/bits/stl_iterator.h: Add move_iterator operators overloads
to make it robust to template abuses.
* testsuite/util/testsuite_greedy_ops.h: New.
* testsuite/23_containers/vector/types/1.cc: Use latter.
* testsuite/23_containers/deque/types/1.cc: Likewise.
* testsuite/24_iterators/move_iterator/greedy_ops.cc: New.
* testsuite/24_iterators/normal_iterator/greedy_ops.cc: New.
* testsuite/24_iterators/reverse_iterator/greedy_ops.cc: New.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
line numbers.
From-SVN: r167580
9 files changed, 280 insertions, 37 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 19bdd55..1447927 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2010-12-07 François Dumont <francois.cppdevs@free.fr> + + * include/bits/stl_iterator.h: Add move_iterator operators overloads + to make it robust to template abuses. + * testsuite/util/testsuite_greedy_ops.h: New. + * testsuite/23_containers/vector/types/1.cc: Use latter. + * testsuite/23_containers/deque/types/1.cc: Likewise. + * testsuite/24_iterators/move_iterator/greedy_ops.cc: New. + * testsuite/24_iterators/normal_iterator/greedy_ops.cc: New. + * testsuite/24_iterators/reverse_iterator/greedy_ops.cc: New. + * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error + line numbers. + 2010-12-06 Paul Pluzhnikov <ppluzhnikov@google.com> PR libstdc++/46830 diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index cf543ba..e930ddb 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1009,42 +1009,81 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return std::move(_M_current[__n]); } }; + // Note: See __normal_iterator operators note from Gaby to understand + // why there are always 2 versions for most of the move_iterator + // operators. template<typename _IteratorL, typename _IteratorR> inline bool operator==(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __x.base() == __y.base(); } + template<typename _Iterator> + inline bool + operator==(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + { return __x.base() == __y.base(); } + template<typename _IteratorL, typename _IteratorR> inline bool operator!=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return !(__x == __y); } + template<typename _Iterator> + inline bool + operator!=(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + { return !(__x == __y); } + template<typename _IteratorL, typename _IteratorR> inline bool operator<(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __x.base() < __y.base(); } + template<typename _Iterator> + inline bool + operator<(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + { return __x.base() < __y.base(); } + template<typename _IteratorL, typename _IteratorR> inline bool operator<=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return !(__y < __x); } + template<typename _Iterator> + inline bool + operator<=(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + { return !(__y < __x); } + template<typename _IteratorL, typename _IteratorR> inline bool operator>(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return __y < __x; } + template<typename _Iterator> + inline bool + operator>(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + { return __y < __x; } + template<typename _IteratorL, typename _IteratorR> inline bool operator>=(const move_iterator<_IteratorL>& __x, const move_iterator<_IteratorR>& __y) { return !(__x < __y); } + template<typename _Iterator> + inline bool + operator>=(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + { return !(__x < __y); } + // DR 685. template<typename _IteratorL, typename _IteratorR> inline auto @@ -1054,6 +1093,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __x.base() - __y.base(); } template<typename _Iterator> + inline auto + operator-(const move_iterator<_Iterator>& __x, + const move_iterator<_Iterator>& __y) + -> decltype(__x.base() - __y.base()) + { return __x.base() - __y.base(); } + + template<typename _Iterator> inline move_iterator<_Iterator> operator+(typename move_iterator<_Iterator>::difference_type __n, const move_iterator<_Iterator>& __x) diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc index c511751..019f5f7 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc @@ -45,7 +45,8 @@ main() // { dg-warning "note" "" { target *-*-* } 1085 } // { dg-warning "note" "" { target *-*-* } 465 } // { dg-warning "note" "" { target *-*-* } 585 } -// { dg-warning "note" "" { target *-*-* } 1027 } +// { dg-warning "note" "" { target *-*-* } 1048 } +// { dg-warning "note" "" { target *-*-* } 1042 } // { dg-warning "note" "" { target *-*-* } 340 } // { dg-warning "note" "" { target *-*-* } 290 } // { dg-warning "note" "" { target *-*-* } 205 } diff --git a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc index 06a326b..eed7f87 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/types/1.cc @@ -20,35 +20,33 @@ // { dg-do compile } #include <deque> - -namespace N -{ - struct X { }; - - template<typename T> - X operator+(T, std::size_t) - { return X(); } - - template<typename T> - X operator-(T, T) - { return X(); } -} +#include <testsuite_greedy_ops.h> int main() { - std::deque<N::X> d(5); - const std::deque<N::X> e(1); + 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, N::X()); - d.insert(d.begin(), N::X()); - d.insert(d.begin(), 1, N::X()); + 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/vector/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc index da02e0c..dd2f8f6 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc @@ -1,6 +1,6 @@ // 2005-12-01 Paolo Carlini <pcarlini@suse.de> -// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// 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 @@ -20,32 +20,20 @@ // { dg-do compile } #include <vector> - -namespace N -{ - struct X { }; - - template<typename T> - X operator+(T, std::size_t) - { return X(); } - - template<typename T> - X operator-(T, T) - { return X(); } -} +#include <testsuite_greedy_ops.h> int main() { - std::vector<N::X> v(5); - const std::vector<N::X> w(1); + 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(), N::X()); - v.insert(v.begin(), 1, N::X()); + 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; diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc new file mode 100644 index 0000000..474a795 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// 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 <testsuite_greedy_ops.h> + +void test01() +{ + typedef std::move_iterator<greedy_ops::X*> iterator_type; + + iterator_type it(nullptr); + + it == it; + it != it; + it < it; + it <= it; + it > it; + it >= it; + it - it; + 1 + it; + it + 1; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc new file mode 100644 index 0000000..23ad57b --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/normal_iterator/greedy_ops.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// 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 <testsuite_greedy_ops.h> + +namespace greedy_ops +{ + struct C + { + typedef X* pointer; + }; +} + +void test01() +{ + typedef __gnu_cxx::__normal_iterator<greedy_ops::X*, + greedy_ops::C> iterator_type; + + iterator_type it(0); + + it == it; + it != it; + it < it; + it <= it; + it > it; + it >= it; + it - it; + it + 1; + 1 + it; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc new file mode 100644 index 0000000..3c7c46f --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/greedy_ops.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// 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 <testsuite_greedy_ops.h> + +void test01() +{ + typedef std::reverse_iterator<greedy_ops::X*> iterator_type; + + iterator_type it; + + it == it; + it != it; + it < it; + it <= it; + it > it; + it >= it; + it - it; + 1 + it; + it + 1; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/util/testsuite_greedy_ops.h b/libstdc++-v3/testsuite/util/testsuite_greedy_ops.h new file mode 100644 index 0000000..8dcbfdb --- /dev/null +++ b/libstdc++-v3/testsuite/util/testsuite_greedy_ops.h @@ -0,0 +1,58 @@ +// 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/>. + +namespace greedy_ops +{ + struct X + { }; + + template<typename T> + X operator==(T, T) + { return X(); } + + template<typename T> + X operator!=(T, T) + { return X(); } + + template<typename T> + X operator<(T, T) + { return X(); } + + template<typename T> + X operator<=(T, T) + { return X(); } + + template<typename T> + X operator>(T, T) + { return X(); } + + template<typename T> + X operator>=(T, T) + { return X(); } + + template<typename T> + X operator-(T, T) + { return X(); } + /* + template<typename T> + T operator+(std::size_t, T) + { return T(); } + */ + template<typename T> + T operator+(T, std::size_t) + { return T(); } +} |