This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: an interesting g++ new/delete bug -- only defining half the set
- To: brendan at cygnus dot com (Brendan Kehoe)
- Subject: Re: an interesting g++ new/delete bug -- only defining half the set
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 27 Aug 1998 18:47:16 -0300
- Cc: egcs-bugs at cygnus dot com
- References: <13795.30721.923819.853436@lisa.cygnus.com>
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