STL vector of enumerated type dies

RHS Linux User ramesh@gvg.vinayagar-systems.com
Thu May 7 12:02:00 GMT 1998


Dear egcs-cists,
 Found a problem with defining vector of enumerated type. Judging from the 
error message it is generic to STL containers.

 Depending on the context two very different error messages appear. I am
enclosing chopped down programs and error messages illustrating both.

regards,
 Ramesh

Here is the code and error message for the template variant of the error:

>-- vec_enum01.cpp
#include <vector>

#define HACK 0

template<class T>
void fn(T sz)
{
  enum tern { H, L, X, U };

#if HACK
  vector<int> ternvec(sz, U); // this not as desireable variant works
#else
  vector<tern> ternvec(sz, U);
#endif

  ternvec[0] = H;
  ternvec[1] = L;
  ternvec[2] = X;

}

main()
{
  int sz = 3;

  fn(sz);
}
>--

>-- compile results 'g++ -v -o it vec_enum01.cpp
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Di386 -D__ELF__ -Dunix -Dlinux -D__i386__ -D__ELF__ -D__unix__ -D__linux__ -D__i386 -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Di386 -Di686 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -D__i686__ -Asystem(unix) -Acpu(i386) -Amachine(i386) vec_enum01.cpp /tmp/cca22114.ii
GNU CPP version egcs-2.90.27 980315 (egcs-1.0.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++
 /usr/local/include
 /usr/local/i686-pc-linux-gnu/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/cc1plus /tmp/cca22114.ii -quiet -dumpbase vec_enum01.cc -version -o /tmp/cca22114.s
GNU C++ version egcs-2.90.27 980315 (egcs-1.0.2 release) (i686-pc-linux-gnu) compiled by GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release).

/usr/local/include/g++/stl_construct.h: In function `void __destroy_aux<fn(T)::tern *>(enum fn(T)::tern *, enum fn(T)::tern *, struct __false_type)':
/usr/local/include/g++/stl_construct.h:52: cannot increment a pointer to incomplete type `fn(T)::tern'
/usr/local/include/g++/stl_vector.h: In method `void vector<fn(T)::tern,__default_alloc_template<true,0> >::deallocate()':
/usr/local/include/g++/stl_vector.h:69: arithmetic on pointer to an incomplete type
/usr/local/include/g++/stl_vector.h:69: invalid use of undefined type `enum fn(T)::tern'
/usr/local/include/g++/stl_alloc.h: In function `static void simple_alloc<fn(T)::tern,__default_alloc_template<true,0> >::deallocate(enum fn(T)::tern *, unsigned int)':
/usr/local/include/g++/stl_alloc.h:225: `sizeof' applied to incomplete type `fn(T)::tern'
vec_enum01.cpp: In function `void fn<int>(int)':
vec_enum01.cpp:13: no matching function for call to `vector<fn(T)::tern,__default_alloc_template<true,0> >::vector (int &, fn<int>(int)::tern)'
/usr/local/include/g++/stl_vector.h:97: candidates are: vector<fn(T)::tern,__default_alloc_template<true,0> >::vector()
/usr/local/include/g++/stl_vector.h:98:                 vector<fn(T)::tern,__default_alloc_template<true,0> >::vector(unsigned int, const fn(T)::tern &)
/usr/local/include/g++/stl_vector.h:99:                 vector<fn(T)::tern,__default_alloc_template<true,0> >::vector(int, const fn(T)::tern &)
/usr/local/include/g++/stl_vector.h:100:                 vector<fn(T)::tern,__default_alloc_template<true,0> >::vector(long int, const fn(T)::tern &)
/usr/local/include/g++/stl_vector.h:101:                 vector<fn(T)::tern,__default_alloc_template<true,0> >::vector(unsigned int)
/usr/local/include/g++/stl_vector.h:103:                 vector<fn(T)::tern,__default_alloc_template<true,0> >::vector(const vector<fn(T)::tern,__default_alloc_template<true,0> > &)
/usr/local/include/g++/stl_vector.h: In method `enum fn(T)::tern & vector<fn(T)::tern,__default_alloc_template<true,0> >::operator [](unsigned int)':
/usr/local/include/g++/stl_vector.h:94: invalid use of undefined type `enum fn(T)::tern'
vec_enum01.cpp: In function `void fn<int>(int)':
vec_enum01.cpp:16: invalid use of undefined type `enum fn(T)::tern'
vec_enum01.cpp:16: warning: conversion from `enum fn<int>(int)::tern' to `enum fn(T)::tern'
vec_enum01.cpp:16: confused by earlier errors, bailing out
>--

Here is the code and error message from a simpler variant

>-- vec_enum00.cpp
#include <vector>

#define HACK 0

main()
{
  enum tern { H, L, X, U };

#if HACK
  vector<int> ternvec(3, U); // this not as desireable variant works
#else
  vector<tern> ternvec(3, U);
#endif

  ternvec[0] = H;
  ternvec[1] = L;
  ternvec[2] = X;

}
>--

>-- result of 'g++ -v -o it vec_enum00.cpp'
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Di386 -D__ELF__ -Dunix -Dlinux -D__i386__ -D__ELF__ -D__unix__ -D__linux__ -D__i386 -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Di386 -Di686 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -D__i686__ -Asystem(unix) -Acpu(i386) -Amachine(i386) vec_enum00.cpp /tmp/cca22111.ii
GNU CPP version egcs-2.90.27 980315 (egcs-1.0.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++
 /usr/local/include
 /usr/local/i686-pc-linux-gnu/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.90.27/cc1plus /tmp/cca22111.ii -quiet -dumpbase vec_enum00.cc -version -o /tmp/cca22111.s
GNU C++ version egcs-2.90.27 980315 (egcs-1.0.2 release) (i686-pc-linux-gnu) compiled by GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release).

vec_enum00.cpp:12: sorry, not implemented: initializer contains unrecognized tree code
vec_enum00.cpp:12: confused by earlier errors, bailing out
>--



More information about the Gcc-bugs mailing list