This is the mail archive of the gcc@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]

Re: Placement new[] weirdness


On 15-Jul-99 Mike Stump wrote:

[snip]

> Yes, bug you failed to mention a single problem (in the form of a
> testcase) that you have.  Sorry, we cannot help you without one.

Well, the following program:

#include <iostream>
#include <new>

struct X
{
  X()
  {}

  ~X()
  {}
};

void main ()
{
#define N 5 
  char p[N*sizeof(X)];
  cout<<(void*)p<<endl;
  X* p1=new(p) X[N];
  cout<<p1<<endl;
}

prints on i586-unknown-linux-gnu:

0xbffff710
0xbffff714

This seems to be not conforming to C++ draft, clause 18.4.1.3 (though conforming
to 5.3.4). Accessing data of array p1 may lead to stack corruption.

Andrey.


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