Template problem (from `iterator_traits')

Lassi A. Tuura lat@iki.fi
Fri Nov 6 08:56:00 GMT 1998


Hi,

I report the following problem but I have no idea whether it is bug in
the code or in the compilers; I do not have access to the standard or a
recent version of the draft right now. 

---- bug.cxx
#include <iterator>
struct X {
  typedef int value_type;
  typedef int difference_type;
  typedef int *pointer;
  typedef int &reference;
  struct I { typedef std::random_access_iterator_tag iterator_category; };
};

int main (int, char **)
{
  std::iterator_traits<X::I>::value_type v = 10;
  std::iterator_traits<X::I>::pointer p = &v;
  std::iterator_traits<X::I>::reference r = *p;
  std::iterator_traits<X::I>::difference_type d = 1;

  p += d; r = 20;
  return r;
}
----

I would expect the compiler look up `value_type' etc. in enclosing
scopes, but KCC 3.3e (on HP-UX 10.20) gives:

"/afs/cern.ch/user/l/lat/public/src/KCC-3.3e/KCC_BASE/include/iterator", line 69: error: 
          class "X::I" has no member "difference_type"
       typedef typename Iterator::difference_type    difference_type;
                                  ^
[snip]

And EGCS 1.1b (on RH5.1 Linux) says:

bug.cxx: In instantiation of `iterator_traits<X::I>':
bug.cxx:12:   instantiated from here
bug.cxx:12: no type named `value_type' in `struct X::I'
[snip]

Any ideas?

Cheers,
//lat
--
With sufficient thrust, pigs fly just fine.  However, this is not
necessarily a good idea.  It is hard to be sure where they are going
to land, and it could be dangerous sitting under them as they fly
overhead.  --RFC1925, "The Twelve Networking Truths"




More information about the Gcc-bugs mailing list