On Wed, Nov 06, 2024 at 01:08:11PM +0100, Jakub Jelinek wrote:
> Though, unsure how that
> https://eel.is/c++draft/expr.new#14
> interacts with
> https://eel.is/c++draft/expr.new#8
> and we'd have to check if we do the size checking before the
> ::operator new/new[] calls or it ::operator new just throws/returns NULL.

I've looked at what code we generate and I guess the -fexceptions
case is fine, ::operator new[] isn't called if there is overflow,
__cxa_throw_bad_array_new_length is called instead.
But for -fno-exceptions it is more problematic, the emitted code
then uses ::operator new but passes ~size_t(0) to it as length and expects
the operator to return NULL (of course, -fno-exceptions is outside of the
standard, but by calling the ::operator new which can be optimized away it
would no longer guarantee returning NULL).
For new (std::nothrow) int[s] with -fexceptions it is even worse,
https://eel.is/c++draft/expr.new#8.6
says it shouldn't call ::operator new[] and instead result in nullptr,
but the code calls __cxa_throw_bad_array_new_length which throws an
exception.

        Jakub

Reply via email to