diff options
author | Paolo Carlini <pcarlini@unitus.it> | 2002-07-02 20:42:58 +0200 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2002-07-02 18:42:58 +0000 |
commit | d16ecaec1d86e2fff32ed93f7d7edffe282878aa (patch) | |
tree | cabfa5c98954dc7baf83609194e53398e44fcf90 | |
parent | 981869348cdca31e489822064dceae769047ef16 (diff) | |
download | gcc-d16ecaec1d86e2fff32ed93f7d7edffe282878aa.zip gcc-d16ecaec1d86e2fff32ed93f7d7edffe282878aa.tar.gz gcc-d16ecaec1d86e2fff32ed93f7d7edffe282878aa.tar.bz2 |
re PR libstdc++/6642 (Constness prevents substraction of iterators)
2002-07-02 Paolo Carlini <pcarlini@unitus.it>
PR libstdc++/6642
* include/bits/stl_iterator.h
(__normal_iterator::operator-(const __normal_iterator&)):
Make non-member, as already happens for the comparison
operators in accord with DR179 (Ready).
* testsuite/24_iterators/iterator.cc: Add test from the PR.
From-SVN: r55188
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 14 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/24_iterators/iterator.cc | 13 |
3 files changed, 32 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cbc4978..873c59b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2002-07-02 Paolo Carlini <pcarlini@unitus.it> + + PR libstdc++/6642 + * include/bits/stl_iterator.h + (__normal_iterator::operator-(const __normal_iterator&)): + Make non-member, as already happens for the comparison + operators in accord with DR179 (Ready). + * testsuite/24_iterators/iterator.cc: Add test from the PR. + 2002-07-02 Phil Edwards <pme@gcc.gnu.org> PR libstdc++/7173 diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index d8a6d8c..6fb0d81 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -629,10 +629,6 @@ namespace __gnu_cxx operator-(const difference_type& __n) const { return __normal_iterator(_M_current - __n); } - difference_type - operator-(const __normal_iterator& __i) const - { return _M_current - __i._M_current; } - const _Iterator& base() const { return _M_current; } }; @@ -719,6 +715,16 @@ namespace __gnu_cxx const __normal_iterator<_Iterator, _Container>& __rhs) { return __lhs.base() >= __rhs.base(); } + // _GLIBCPP_RESOLVE_LIB_DEFECTS + // According to the resolution of DR179 not only the various comparison + // operators but also operator- must accept mixed iterator/const_iterator + // parameters. + template<typename _IteratorL, typename _IteratorR, typename _Container> + inline typename __normal_iterator<_IteratorL, _Container>::difference_type + operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, + const __normal_iterator<_IteratorR, _Container>& __rhs) + { return __lhs.base() - __rhs.base(); } + template<typename _Iterator, typename _Container> inline __normal_iterator<_Iterator, _Container> operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, diff --git a/libstdc++-v3/testsuite/24_iterators/iterator.cc b/libstdc++-v3/testsuite/24_iterators/iterator.cc index 98aa8c0..7acd1ec 100644 --- a/libstdc++-v3/testsuite/24_iterators/iterator.cc +++ b/libstdc++-v3/testsuite/24_iterators/iterator.cc @@ -577,6 +577,17 @@ wrong_stuff() return failures; } +// libstdc++/6642 +int +test6642() +{ + std::string s; + std::string::iterator it = s.begin(); + std::string::const_iterator cit = s.begin(); + + return it - cit; +} + int main(int argc, char **argv) { @@ -590,6 +601,8 @@ main(int argc, char **argv) failures += wrong_stuff(); + failures += test6642(); + #ifdef DEBUG_ASSERT assert (failures == 0); #endif |