g++ bug?

Roberto Bagnara bagnara@di.unipi.it
Fri Apr 10 10:25:00 GMT 1998


Hi there,

the following typescript illustrates what can be a bug
in egcs/g++ and/or libstdc++.
egcs/g++ exhibits this behavior since the very first release.

Script started on Fri Apr 10 16:31:06 1998
$ uname -a
Linux blip 2.0.32 #6 Sun Mar 22 22:05:21 CET 1998 i586 unknown
$ g++ -v
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
$ cat bug.cc

#include <vector>

class SimpleRemapMap : private vector<int> {
private:
  typedef vector<int> Base;
public:
  int size() const;
  void insert(int varid1, int varid2);
};

inline int
SimpleRemapMap::size() const {
  return Base::size();
}

inline void
SimpleRemapMap::insert(int varid1, int varid2) {
  if (varid1 > size())
    Base::insert(end(), varid1 - size(), -1);
  if (varid1 == size()) {
    Base::insert(end(), varid2);
    return;
  }
  int& v = Base::operator[](varid1);
  assert(v == -1);
  v = varid2;
}

$ g++ bug.cc
/usr/local/include/g++/stl_vector.h:171: no type named `iterator_category' in
`int'
/usr/local/include/g++/stl_vector.h:171: no type named `value_type' in `int'
/usr/local/include/g++/stl_vector.h:171: no type named `difference_type' in
`int'
/usr/local/include/g++/stl_vector.h:171: no type named `pointer' in `int'
/usr/local/include/g++/stl_vector.h:171: no type named `reference' in `int'
/usr/local/include/g++/stl_iterator.h: In function `{error}
iterator_category<int>(const int &)':
/usr/local/include/g++/stl_iterator.h:126: confused by earlier errors, bailing
out
$ exit
exit

Script done on Fri Apr 10 16:31:38 1998

Notes:

1) I know I haven't to redefine size() that way to make
   it public;
2) I am not sure it is legal code. Probably it is.
   However, I understand it is casting vector<int>::size()
   to int and this causes problems.
3) The problem goes away if in stl_config.h one pretends that
   egcs/g++ does not support template members of classes.

Keep up the good work

       Roberto

-- 
Roberto Bagnara
Department of Mathematics, University of Parma, Italy
http://www.di.unipi.it/~bagnara/bagnara.html
mailto:bagnara@di.unipi.it



More information about the Gcc-bugs mailing list