[v3] Fix libstdc++/6642

Paolo Carlini pcarlini@unitus.it
Tue Jul 2 11:46:00 GMT 2002


Hi,

after testing on i686-pc-linux-gnu I have committed to trunk the below, 
approved by Phil Edwards and Benjamin Kosnik.

Ciao, Paolo.

//////////

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.

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_iterator.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- gcc/libstdc++-v3/include/bits/stl_iterator.h	2002/04/16 02:29:20	1.20
+++ gcc/libstdc++-v3/include/bits/stl_iterator.h	2002/07/02 18:42:57	1.21
@@ -629,10 +629,6 @@
       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; }
     };
@@ -718,6 +714,16 @@
   operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
 	     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>

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/24_iterators/iterator.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- gcc/libstdc++-v3/testsuite/24_iterators/iterator.cc	2001/11/23 16:29:01	1.5
+++ gcc/libstdc++-v3/testsuite/24_iterators/iterator.cc	2002/07/02 18:42:58	1.6
@@ -577,6 +577,17 @@
    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)
 {
@@ -589,6 +600,8 @@
    failures += reverse_stuff();
 
    failures += wrong_stuff();
+
+   failures += test6642();
 
 #ifdef DEBUG_ASSERT
    assert (failures == 0);




More information about the Gcc-patches mailing list