This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

ICE on g++


This causes an ICE on g++ when std::vector's iterator is not a class
that you can derive form (ie, wne it is a plain pointer. Older versions
of linstdc++ had this feature). I'm using g++3.2.2.

<FILE ATTACHED>
Any ideas?

ps. Please cc the message to me, since I'm not subscribed.


-- 
	-Dhruv Matani.
http://www.geocities.com/dhruvbird/


#include <vector>
#include <iterator>
//#include <iostream>
#include <cstdlib>
// #include <list>
// #include <nstl/list.hpp>


namespace nstd {


struct alloc {
  void* (*new_fn__)(std::size_t);
  void (*del_fn__) (void*);
  template <class Alloc_Fn, class Del_Fn>
  alloc (Alloc_Fn af_, Del_Fn df_) : new_fn__(af_), del_fn__(df_) { }
};


template <class Type, class Allocator = std::allocator<Type*> >
class auto_vector : public std::vector<Type*, Allocator> {

  typedef typename nstd::auto_vector<Type, Allocator> This_Type;
  typedef typename std::vector<Type*, Allocator> Base;

  //Assume that iterator is a class/struct, from which we can derive
  //stuff.
  template <class IteratorB_, class Ref_Type, class Ptr_Type>
  class ptr_iterator : public IteratorB_ {
    typedef IteratorB_ Iterator_Base;
    typedef ptr_iterator<Iterator_Base, Ref_Type, Ptr_Type> Self_Type;
    typedef ptr_iterator<Iterator_Base,
			 typename std::iterator_traits<Iterator_Base>::value_type&,
			 typename std::iterator_traits<Iterator_Base>::value_type*> 
    iterator;
    typedef ptr_iterator<Iterator_Base,
			 const typename std::iterator_traits<Iterator_Base>::value_type&,
			 const typename std::iterator_traits<Iterator_Base>::value_type*> 
    const_iterator;


  public:
    ptr_iterator () { }
    ptr_iterator (Iterator_Base IB_) : Iterator_Base (IB_) { }
    ptr_iterator (const iterator& IB_) : Iterator_Base (IB_) { }
    Ref_Type operator* () { return *(Iterator_Base::operator*()); }

  };


public:
  typedef typename Base::value_type value_type;
  typedef typename Base::const_reference const_reference;
  typedef typename This_Type::ptr_iterator<typename Base::iterator,
					   Type&, Type*> iterator;
  typedef typename This_Type::ptr_iterator<typename Base::iterator,
					   const Type&, const Type*> const_iterator;



//   void push_back (const_reference data)
//   {
//     std::cout<<"In the derived function"<<std::endl;
//     Base::push_back (data);
//   }

  iterator begin() { return static_cast<iterator> (Base::begin ()); }
  ~auto_vector ()
  {
    typename Base::iterator rover = Base::begin ();
    typename Base::iterator last = Base::end ();
    while (rover != last) {
      delete *rover;
      ++rover;
    }
  }
};
}

// struct foo_base {
// };

// template <class Type, class RT>
// struct foo : public foo_base {
//   int x;
//   foo ():x(0) { }
//   foo (int _x) : x(_x) { }
//   foo (const foo<Type, Type&>&):x(0) { }
// };


int main ()
{
  //nstd::alloc (malloc, free) a;

//   foo<int, int&> fi;
//   foo <int, const int&> cfi = fi;

  nstd::auto_vector<int> avi;
  avi.push_back (new int(23));
  avi.push_back (new int(55));
  nstd::auto_vector<int>::iterator iter = avi.begin();
  nstd::auto_vector<int>::const_iterator iter1 = avi.begin();
  bool b = iter < iter1;
  //  ++iter; --iter;
  iter = iter + 1;
  iter = iter > avi.begin()?avi.begin():iter;
  //std::cout<<*iter;
//   nstd::list<int> il (1, 23);
//   nstd::list<int>::const_iterator iter = il.begin();
}


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