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]

Re: an interesting g++ new/delete bug -- only defining half the set


Brendan Kehoe <brendan@cygnus.com> writes:

> #include <new>
> extern "C" void printf (char *, ...);
> void *operator new( size_t size, const nothrow_t&) throw()
> 	{ printf ("new %d nothrow\n", size); return (void*)-1; }
> main () { int *x = new (nothrow) (int); delete x; }

> What it will very subtly do is call your redefined operator new, but
> then call your builtin operator delete.

Which is correct.  Even if you had redefined operator delete(void*,
const nothrow_t&), it would only have been used if the constructor of
the newed type had thrown an exception.  A delete expression will
never cause the invocation of any form of a placement delete operator.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



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