This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Serious new (type-id) bug


I am using egcs on OpenBSD.  All versions of egcs I have tried seem to
have serious problems dealing with new expressions in which the
type-id is in parentheses.  For example, the attached program should
print:

one 1
one 2
one 3
one 4
one 5

With egcs, however, it prints anything but.  Depending on the version
of egcs and the level of optimization, I've seen everything from
allocating a single "one" object, to allocating more than 10
(triggering an assertion failure), to an outright abort.  It never
does the right thing, however.

If the parentheses are removed from the new expression, giving "new
new-type-id", then things work fine:

  two (int a) : ov (new one[a]) {}

As far as I can tell from 5.3.4, any type-id that qualifies as a
new-type-id should behave identically in a new-expression whether or
not it is enclosed in parentheses.  Admittedly I've misinterpreted the
standard before.  Here, hoever, I really don't see any other
interpetation for the meaning of "new (one[a])".  "one[a]" can't be a
new-placement, because the new-type-id / (type-id) would be missing,
and it is not optional.  Also, for what it's worth, Sun's C++ compiler
seems to give the expected behavior on the code below.

===

#include <stdio.h>
#include <assert.h>

int ctr;
struct one {
  one () {
    assert (ctr < 10);
    fprintf (stderr, "one %d\n", ++ctr);
  }
};

class two {
  one *ov;
public:
  two (int a) : ov (new (one[a])) {}
};

int
main ()
{
  new two (5);
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]