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: Marc Glisse <marc dot glisse at inria dot fr>
- To: Mike Stump <mikestump at comcast dot net>, Martin Sebor <msebor at gmail dot com>
- Cc: Daniel Gutson <daniel dot gutson at tallertechnologies dot com>, Aurelio Remonda <aurelio dot remonda at tallertechnologies dot com>, 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, Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Date: Wed, 4 Nov 2015 09:07:29 +0100 (CET)
- 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> <563922C6 dot 7080706 at gmail dot com> <3937336D-6170-4513-A658-A2835E87FB0C at comcast dot net> <5639482B dot 1050309 at gmail dot com>
- Reply-to: libstdc++ at gcc dot gnu dot org
On Tue, 3 Nov 2015, Mike Stump wrote:
On Nov 3, 2015, at 1:10 PM, Martin Sebor <msebor@gmail.com> wrote:
The "as if" requirement implies that any observable effects of
"the (possibly replaced) ordinary version" must be preserved.
The repeated calls to the new handler are among such effects.
Unless the standard is fixed to say that one cannot observe the repeated
calls. We do this in some places, for some things:
[snip copy elision]
in C++, so, it isnʼt out of the question. I was looking for dynamic ->
static object optimization wording, but didnʼt find it in the first C++
standard. That is a fairly reasonable thing to do, and if done well,
can reasonably change the observable side-effects as well.
There is recent-ish wording in [expr.new] that says that 'new int' is not
forced to call operator new. However, operator new (which can be called
directly) has a rather strictly defined behavior. And a bad one at that,
since it forces the use of an exception to report an error to the direct
caller...
On Tue, 3 Nov 2015, Martin Sebor wrote:
There are two sets of important observable effects: the calls to
the handler, and the call to the (possibly replaced) ordinary
operator new.
"This nothrow version of operator new returns a pointer obtained as if
acquired from the (possibly replaced) ordinary version."
For a non-native speaker, it is extremely unclear if the (possibly
replaced) ordinary version is the original one that has been displaced or
if it is the user one that did the replacement.
A C++ program is allowed to replace just the ordinary operator
new (and not the nothrow version), call the default nothrow
operator new, and expect to get back the same pointer that would
have been returned from the replaced new had it been called instead.
(Some implementations, including libstdc++, fail to conform to this
requirement.)
That's also the interpretation I remember, and I find it contradictory
with the C++ philosophy that exceptions are heavy, expensive, and should
be avoided for local use. (of course allocation failure should be rare)
--
Marc Glisse