diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 19bdd55f1756ccbc09e3b412768b847e0fe64a8b..14479272f27c87b86b1c9050b0be0cac42ee85a9 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 cf543baebd0e244c907e9d6f07105cd78c0bf0f8..e930ddbd219b494106896423d2d2e67bcf088a3d 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 @@ -1053,6 +1092,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) -> decltype(__x.base() - __y.base()) { 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, 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 c511751f343b4fa17b9854d689682711b883b802..019f5f7f592e377f50fa4f927ba752abd75cc70e 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 06a326ba8eeb00cc61778c51330fb2a44fe8ae81..eed7f873549e708275641d65eeaeb8f181967e9d 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 da02e0cfd34847a53c5e9d71b93abb29dbe38aa6..dd2f8f6466883207e478fbab58909d54c63c7b9b 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 0000000000000000000000000000000000000000..474a795abda8edd9a2b8c4ed8dbe7dbde872a31b --- /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 0000000000000000000000000000000000000000..23ad57b9789e5c46af846e391414e767f30cb4f5 --- /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 0000000000000000000000000000000000000000..3c7c46fdef9826d0469da2a6a5e088abffb1a711 --- /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 0000000000000000000000000000000000000000..8dcbfdb84eacdac5e637b5e2e725988e234f8f83 --- /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(); } +}