new type (initializer) --- bug ???

Ruediger Schopper
Tue Oct 13 05:48:00 GMT 1998


I have found the following Problem, which is new in
the current revision of egcs-g++. 

When one gives an initializer to the new operator, it
compiles with aggregate types, but not with built in ones.

The following code:

#include <stream.h>
#include <new>

class test {
  double d;
  test() : d(0.0) {};
  test(double a) : d(a) {};

int main () {

  test*   da=new test[2](5.0);
  double* dp=new double[2](1.0);

  cout << *dp << "\t"
       << da[0].d << "\t"
       << da[1].d << endl;

compiled with the command "g++ -v" produces the following

Reading specs from /usr/users/schopper/local/lib/gcc-lib/alphaev5-dec-osf4.0d/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
 /usr/users/schopper/local/lib/gcc-lib/alphaev5-dec-osf4.0d/egcs-2.91.57/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -Dunix -D__osf__ -D_LONGLONG -DSYSTYPE_BSD -D_SYSTYPE_BSD -D__unix__ -D__osf__ -D_LONGLONG -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__unix -D__SYSTYPE_BSD -Asystem(unix) -Asystem(xpg4) -D__EXCEPTIONS -D__LANGUAGE_C_PLUS_PLUS__ -D__LANGUAGE_C_PLUS_PLUS -D__cplusplus -Acpu(alpha) -Amachine(alpha) -D__alpha -D__alpha__ -D__alpha_ev5__ -Acpu(ev5) /usr/users/schopper/local/tmp/cc9zRCyU.ii
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release)
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /usr/users/schopper/local/lib/gcc-lib/alphaev5-dec-osf4.0d/egcs-2.91.57/cc1plus /usr/users/schopper/local/tmp/cc9zRCyU.ii -quiet -dumpbase -version -o /usr/users/schopper/local/tmp/cciD4oR2.s
GNU C++ version egcs-2.91.57 19980901 (egcs-1.1 release) (alphaev5-dec-osf4.0d) compiled by GNU C version egcs-2.91.57 19980901 (egcs-1.1 release). In function `int main()': request for member `__ct' in `*{anon}', which is of non-aggregate type `double'

This "bug" is especially problematic, if one tries to write
a template function with 

template <class T>
test (T x, T init=T()) { 

T*  bla = new T[20] (init);

in it, because one can't know what type the user will chose. 

Most interesting is the fact, that this error has occured after
installing this revision. In a previous one (sorry don't know which)
there was no such problem.

I don't know if this is a bug or anything else.

 Ruediger Schopper

More information about the Gcc-bugs mailing list