1.0.2 bug?

Tomislav Goles tom@ait-tech.com
Tue Apr 7 18:45:00 GMT 1998


Can someone please take a look at the short template example below and explain
the error message g++ produces (I think the code is correct and compiler is wrong).

// foo.cpp
#include <string>
#include <vector>
typedef vector< vector< string > >::const_iterator Iterator;
int Mid( Iterator first, Iterator last )
{
  int mid = ( last - first ) / 2;
  return( mid );
}

% g++ -v
Reading specs from /usr/local/egcs/lib/gcc-lib/hppa1.1-hp-hpux10.01/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)

% g++ -o foo.o foo.cpp
foo.cpp: In function `int Mid(const class vector<basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> >,__default_alloc_template<false,0> > *, const class vector<basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> >,__default_alloc_template<false,0> > *)':
foo.cpp:7: arithmetic on pointer to an incomplete type
foo.cpp:7: invalid use of undefined type `class vector<basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> >,__default_alloc_template<false,0> >'


To make things even more confusing (at least to me), the following compiles
fine (notice that I only changed the typedef line with the template line and
the rest of the code is the same):

// foo.cpp
#include <string>
#include <vector>
template< class Iterator=vector< vector< string > >::const_iterator >
int Mid( Iterator first, Iterator last )
{
  int mid = ( last - first ) / 2;
  return( mid );
}



More information about the Gcc-bugs mailing list