This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/14340


This test case in libstdc++/14340 was failing because this converting 
constructor is a bit too lenient:

  template<typename _MutableIterator>
    _Safe_iterator(const _Safe_iterator<_MutableIterator, _Sequence>& __x);

The attached patch (against gcc-3_4-branch: changelog below) tightens the 
declaration of the converting constructor so that the declaration only 
matches exactly the right types. I've only done basic testing on 
i686-pc-linux-gnu because I'm not currently set up for real testing. 

	Doug


2004-05-14  Douglas Gregor   <gregod@cs.rpi.edu>

	PR libstdc++/14340 
	* include/debug/safe_iterator.h (_Safe_iterator converting 
	constructor): Only allow declaration to instantiate when the 
	incoming _Safe_iterator has exactly the right iterator type.
Index: include/debug/safe_iterator.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/debug/safe_iterator.h,v
retrieving revision 1.2.8.1
diff -u -r1.2.8.1 safe_iterator.h
--- include/debug/safe_iterator.h	16 Apr 2004 19:08:34 -0000	1.2.8.1
+++ include/debug/safe_iterator.h	14 May 2004 05:10:06 -0000
@@ -35,6 +35,7 @@
 #include <debug/debug.h>
 #include <debug/formatter.h>
 #include <debug/safe_base.h>
+#include <bits/cpp_type_traits.h>
 
 namespace __gnu_debug
 {
@@ -88,6 +89,7 @@
       typedef iterator_traits<_Iterator> _Traits;
 
     public:
+      typedef _Iterator                           _Base_iterator;
       typedef typename _Traits::iterator_category iterator_category;
       typedef typename _Traits::value_type        value_type;
       typedef typename _Traits::difference_type   difference_type;
@@ -132,7 +134,13 @@
        *  @pre @p x is not singular
       */
       template<typename _MutableIterator>
-        _Safe_iterator(const _Safe_iterator<_MutableIterator, _Sequence>& __x)
+        _Safe_iterator(
+          const _Safe_iterator<_MutableIterator,
+          typename std::__enable_if<
+                     _Sequence,
+                     (std::__are_same<_MutableIterator,
+                      typename _Sequence::iterator::_Base_iterator>::_M_type)
+                   >::_M_type>& __x)
 	: _Safe_iterator_base(__x, _M_constant()), _M_current(__x.base())
         {
 	  _GLIBCXX_DEBUG_VERIFY(!__x._M_singular(),

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]