egcs-19981101: new T[1] neglects to call constructor!!?!

Corey Kosak kosak@cs.cmu.edu
Sat Nov 7 00:27:00 GMT 1998


% g++ -v
Reading specs from /afs/cs.cmu.edu/project/cmcl-kosak/various-gcc/egcs-19981101/alpha_dux40/lib/gcc-lib/alpha-dec-osf4.0d/egcs-2.92.18/specs
gcc version egcs-2.92.18 19981101 (gcc2 ss-980609 experimental)

% cat test.cc
#include <stdio.h>

struct cow_t {
  cow_t()            { printf("Constructing a cow_t\n"); }
  virtual void Moo() { printf("Inside Moo()\n"); }
};

int main()
{
  cow_t *cowp = new cow_t[SIZE];
  cowp[0].Moo();
  return 0;
}

% g++ -DSIZE=2 test.cc && a.out
Constructing a cow_t
Constructing a cow_t
Inside Moo()

% g++ -DSIZE=1 test.cc && a.out
Segmentation fault



More information about the Gcc-bugs mailing list