c++/1631: placement new broken for enumeration types

Frederik Schaffalitzky fsm@robots.ox.ac.uk
Fri Jan 12 17:30:00 GMT 2001


A more minimal example that tickles the bug is:
  enum X { alpha, beta };
  void *operator new (unsigned, void *p) { return p; } //#include <new>
  void f()
  {
    char bytes[sizeof(X)];
    new (bytes) X();    // <-- error reported here
  }

which produces the result
  $ g++ -c enum.cxx
  enum.cxx: In function `void f()':
  enum.cxx:6: cannot convert `int' to `X' in initialization

E.g. it is impossible to instantiate std::vector<X> from the current
libstdc++ because of std::construct().



As far as I can see, the problem could be caused by two factors:

1. The arguments to X() are (correctly?) represented by "void_zero_node"
in parse.y by reduction of LEFT_RIGHT, but build_default_init() modifies
this to "integer_zero_node" in order to zero-initialize the object. I
think that is the reason the compiler later claims that an X is being
initialized from an int.

2. In call.c, near the end of standard_conversion(), it says:
  .....
	ICS_STD_RANK (conv) = PBOOL_RANK;
    }
  /* We don't check for ENUMERAL_TYPE here because there are no standard
     conversions to enum type.  */
  else if (tcode == INTEGER_TYPE || tcode == BOOLEAN_TYPE
	   || tcode == REAL_TYPE)
    {
      if (! (INTEGRAL_CODE_P (fcode) || fcode == REAL_TYPE))
  .....
which appears to be the place where the compiler first decides that the
conversion can't take place.

Maybe this is of use. If not, it was fun to find out.

Frederik

$ g++ -v 
Reading specs from
./CVSgcc/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/2.97/specs
Configured with: ../gcc/configure --prefix=/homes/az2/fsm/CVSgcc/install
--srcdir=/homes/az2/fsm/CVSgcc/gcc --enable-shared --with-shared
gcc version 2.97 20010111 (experimental)






On 12 Jan 2001 gcc-gnats@gcc.gnu.org wrote:

> Thank you very much for your problem report.
> It has the internal identification `c++/1631'.
> The individual assigned to look at your
> report is: unassigned. 
> 
> >Category:       c++
> >Responsible:    unassigned
> >Synopsis:       placement new broken for enumeration types
> >Arrival-Date:   Fri Jan 12 07:06:00 PST 2001



More information about the Gcc-bugs mailing list