On Tue, 3 Aug 2021 at 18:26, Modi Mo via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi all,
>
> I recently committed support for the "-fnew-infallible" flag in Clang 
> (https://reviews.llvm.org/D105225) to improve non-exceptional performance for 
> code that contains exceptions. Having "new" terminate immediately on failure 
> stops upward exception propagation and leads to significantly less landing 
> pads generated. Posting here for visibility and to reduce the chance that a 
> similar feature may manifest under a different flag for GCC.

Thanks for the heads up. This is interesting.

Could you explain this sentence in the commit message:
"Note that the definition of global new is user-replaceable so users
should ensure that the one used follows these semantics."

What happens if operator new does throw? Is that just treated like any
other noexcept function that throws, i.e. std::terminate()? Or is it
undefined behaviour?

And what if you use ::new(std::nothrow) and that fails, returning
null. Is that undefined?

It seems to me that the former case (a potentially-throwing allocation
function) could be turned into a std::terminate call fairly easily
without losing the benefits of this option (you still know that no
call to operator new will propagate exceptions). But for the latter
case the program *must* replace operator new to ensure that the
nothrow form never returns null, otherwise you violate the promise
that the returns_nonnull attribute makes, and have undefined
behaivour. Is that right?

Reply via email to