https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78822

Pedro Alves <palves at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |palves at redhat dot com

--- Comment #19 from Pedro Alves <palves at redhat dot com> ---
> The reason for ensuring xmalloc_failed is used is to get sane and consistent 
> behavior on memory allocation failures (same error message with the same 
> detail), rather than just crashing the compiler, or saying terminate has been 
> called and similar.

You can replace the global operator new/new[] to call xmalloc instead of
malloc.  Then memory allocation by std::string etc. ends up in xmalloc ->
xmalloc_failed.  That's what I did for GDB:

 
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/common/new-op.c;h=c67239cbe87c1f7e22e234a1a2cc2920f9ed22a4;hb=HEAD

Replacing global new is better than installing a new_handler that calls
xmalloc_failed with std::set_new_handler, IMO, since replacing global new
handles allocation in global static constructors too.
OTOH, dynamic allocation in global objects is best avoided anyway, so you can
always go the std::set_new_handler route if replacing global new doesn't work
on some non-confirming host.

Reply via email to