This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
an interesting g++ new/delete bug -- only defining half the set
- To: egcs-bugs at cygnus dot com
- Subject: an interesting g++ new/delete bug -- only defining half the set
- From: Brendan Kehoe <brendan at cygnus dot com>
- Date: Tue, 25 Aug 1998 19:50:41 -0700 (PDT)
- Reply-To: brendan at cygnus dot com (Brendan Kehoe)
Say you have code that does
#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. The program will usually segfault, bus error,
or the equivalent. (By forcing -1, we make sure we die. :) )
Any thoughts on a productive way to make the compiler see that this is
happening, and suitably warn about it? Like have both build_new and
build_delete do a DECL_BUILT_IN check between what would be called for that
type, versus what will probably be used for its opposite? Hmm...
B