mirror of git://gcc.gnu.org/git/gcc.git
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
This commit is contained in:
parent
2b843fad50
commit
f38716953d
|
|
@ -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>
|
2010-12-06 Paul Pluzhnikov <ppluzhnikov@google.com>
|
||||||
|
|
||||||
PR libstdc++/46830
|
PR libstdc++/46830
|
||||||
|
|
|
||||||
|
|
@ -1009,42 +1009,81 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
{ return std::move(_M_current[__n]); }
|
{ 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>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline bool
|
inline bool
|
||||||
operator==(const move_iterator<_IteratorL>& __x,
|
operator==(const move_iterator<_IteratorL>& __x,
|
||||||
const move_iterator<_IteratorR>& __y)
|
const move_iterator<_IteratorR>& __y)
|
||||||
{ return __x.base() == __y.base(); }
|
{ 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>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline bool
|
inline bool
|
||||||
operator!=(const move_iterator<_IteratorL>& __x,
|
operator!=(const move_iterator<_IteratorL>& __x,
|
||||||
const move_iterator<_IteratorR>& __y)
|
const move_iterator<_IteratorR>& __y)
|
||||||
{ return !(__x == __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>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline bool
|
inline bool
|
||||||
operator<(const move_iterator<_IteratorL>& __x,
|
operator<(const move_iterator<_IteratorL>& __x,
|
||||||
const move_iterator<_IteratorR>& __y)
|
const move_iterator<_IteratorR>& __y)
|
||||||
{ return __x.base() < __y.base(); }
|
{ 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>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline bool
|
inline bool
|
||||||
operator<=(const move_iterator<_IteratorL>& __x,
|
operator<=(const move_iterator<_IteratorL>& __x,
|
||||||
const move_iterator<_IteratorR>& __y)
|
const move_iterator<_IteratorR>& __y)
|
||||||
{ return !(__y < __x); }
|
{ 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>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline bool
|
inline bool
|
||||||
operator>(const move_iterator<_IteratorL>& __x,
|
operator>(const move_iterator<_IteratorL>& __x,
|
||||||
const move_iterator<_IteratorR>& __y)
|
const move_iterator<_IteratorR>& __y)
|
||||||
{ return __y < __x; }
|
{ 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>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline bool
|
inline bool
|
||||||
operator>=(const move_iterator<_IteratorL>& __x,
|
operator>=(const move_iterator<_IteratorL>& __x,
|
||||||
const move_iterator<_IteratorR>& __y)
|
const move_iterator<_IteratorR>& __y)
|
||||||
{ return !(__x < __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.
|
// DR 685.
|
||||||
template<typename _IteratorL, typename _IteratorR>
|
template<typename _IteratorL, typename _IteratorR>
|
||||||
inline auto
|
inline auto
|
||||||
|
|
@ -1053,6 +1092,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
-> decltype(__x.base() - __y.base())
|
-> decltype(__x.base() - __y.base())
|
||||||
{ return __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>
|
template<typename _Iterator>
|
||||||
inline move_iterator<_Iterator>
|
inline move_iterator<_Iterator>
|
||||||
operator+(typename move_iterator<_Iterator>::difference_type __n,
|
operator+(typename move_iterator<_Iterator>::difference_type __n,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ main()
|
||||||
// { dg-warning "note" "" { target *-*-* } 1085 }
|
// { dg-warning "note" "" { target *-*-* } 1085 }
|
||||||
// { dg-warning "note" "" { target *-*-* } 465 }
|
// { dg-warning "note" "" { target *-*-* } 465 }
|
||||||
// { dg-warning "note" "" { target *-*-* } 585 }
|
// { 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 *-*-* } 340 }
|
||||||
// { dg-warning "note" "" { target *-*-* } 290 }
|
// { dg-warning "note" "" { target *-*-* } 290 }
|
||||||
// { dg-warning "note" "" { target *-*-* } 205 }
|
// { dg-warning "note" "" { target *-*-* } 205 }
|
||||||
|
|
|
||||||
|
|
@ -20,35 +20,33 @@
|
||||||
// { dg-do compile }
|
// { dg-do compile }
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <testsuite_greedy_ops.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()
|
int main()
|
||||||
{
|
{
|
||||||
std::deque<N::X> d(5);
|
std::deque<greedy_ops::X> d(5);
|
||||||
const std::deque<N::X> e(1);
|
const std::deque<greedy_ops::X> e(1);
|
||||||
|
|
||||||
d[0];
|
d[0];
|
||||||
e[0];
|
e[0];
|
||||||
d.size();
|
d.size();
|
||||||
d.erase(d.begin());
|
d.erase(d.begin());
|
||||||
d.resize(1);
|
d.resize(1);
|
||||||
d.assign(1, N::X());
|
d.assign(1, greedy_ops::X());
|
||||||
d.insert(d.begin(), N::X());
|
d.insert(d.begin(), greedy_ops::X());
|
||||||
d.insert(d.begin(), 1, N::X());
|
d.insert(d.begin(), 1, greedy_ops::X());
|
||||||
d.insert(d.begin(), e.begin(), e.end());
|
d.insert(d.begin(), e.begin(), e.end());
|
||||||
d = e;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// 2005-12-01 Paolo Carlini <pcarlini@suse.de>
|
// 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
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
// software; you can redistribute it and/or modify it under the
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
|
@ -20,32 +20,20 @@
|
||||||
// { dg-do compile }
|
// { dg-do compile }
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <testsuite_greedy_ops.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()
|
int main()
|
||||||
{
|
{
|
||||||
std::vector<N::X> v(5);
|
std::vector<greedy_ops::X> v(5);
|
||||||
const std::vector<N::X> w(1);
|
const std::vector<greedy_ops::X> w(1);
|
||||||
|
|
||||||
v[0];
|
v[0];
|
||||||
w[0];
|
w[0];
|
||||||
v.size();
|
v.size();
|
||||||
v.capacity();
|
v.capacity();
|
||||||
v.resize(1);
|
v.resize(1);
|
||||||
v.insert(v.begin(), N::X());
|
v.insert(v.begin(), greedy_ops::X());
|
||||||
v.insert(v.begin(), 1, N::X());
|
v.insert(v.begin(), 1, greedy_ops::X());
|
||||||
v.insert(v.begin(), w.begin(), w.end());
|
v.insert(v.begin(), w.begin(), w.end());
|
||||||
v = w;
|
v = w;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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(); }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue