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]
Other format: [Raw text]

[Bug c++/12238] placement delete not called on incomplete object construction if in try-block!


------- Additional Comments From rmerkert at alphatech dot com  2003-12-31 02:39 -------
I think the code is not correct:

The corresponding placement delete for new (size_t, allocator) should be
delete (void*,allocator) and not delete(void*,size_t,allocator).

Here's a simplified version of the code (I've omitted the array version, and the
placement operators are global):
#include <cstdlib>

#define BUG

struct A
{
  A() { throw 1; } 
};

void* operator new(::size_t,double)
{
  static char memory[64];
  return memory;
}

#ifdef BUG
void operator delete(void*,size_t,double)
#else
void operator delete(void*,double)
#endif
{
  ::std::exit(0);
}

int main()
{
  try
    {
      new(0.0) A();
    }
  catch(...)
    {}

  ::std::abort();
}

If the incorrect placement delete is used, then no delete function is invoked
whatsoever. Maybe a warning is in order?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12238


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