This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add configure flag for operator new (std::nothrow)
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Daniel Gutson <daniel dot gutson at tallertechnologies dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Aurelio Remonda <aurelio dot remonda at tallertechnologies dot com>, "libstdc++" <libstdc++ at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, daniel dot gutston at tallertechnologies dot com
- Date: Wed, 4 Nov 2015 11:50:16 +0530
- Subject: Re: [PATCH] Add configure flag for operator new (std::nothrow)
- Authentication-results: sourceware.org; auth=none
- References: <1446554133-3090-1-git-send-email-aurelio dot remonda at tallertechnologies dot com> <56391843 dot 1070807 at gmail dot com> <CAF5HaEVeD4G1Mj8GwbpLyZ8V+GWNRAy1=5qbfVHgrZ=GpkbHbg at mail dot gmail dot com>
On 4 November 2015 at 02:11, Daniel Gutson wrote:
> Since this is a nothrow new, we thought that probably the system
> might not be exceptions-friendly (such as certain embedded systems),
> so we wanted to provide the new_handler the ability to do something else
> other than trying to allocate memory and keep the function iterating.
That could be done using an alternative overload of operator new
instead of altering the semantics of the standard one (that could be
provided as a GNU extension, for example).
> In fact, our idea is that since the nothrow new can indeed return nullptr,
> let the new_handler do something else and leave the no-memory-consequence
> to the caller.
> This new flag enables just that.
The default configuration already allows the caller to deal with
allocation failure from the nothrow version of new, by not installing
a new-handler installed, and dealing with a null return value. How
would I use this alternative configuration? Since the behaviour only
changes when a new-handler is installed, presumably I'm meant to
install some kind of new-handler that does something else ... but
what? The patch should include documentation explaining when and how
to use this option.