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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #3)
> I suspect 'operator new' is not returns_nonnull for the variant that isn't
> noexcept.  That would be my first stab at improving things.  Not sure
> what the standard guarantees and where we can adjust things here?

The standard guarantees that the noexcept(false) operator new returns nonnull
or throws, it never returns null.

I thought that was already implicitly returns_nonnull, but maybe not the FE
just treats it as non-null for the new-expression, but that info doesn't make
it into the IR.

I don't think we can just add the attribute in the library because of:

       -fcheck-new
           Check that the pointer returned by "operator new" is non-null before
attempting to modify the storage allocated.  This check is normally unnecessary
because the C++ standard specifies that "operator new" only returns 0 if it is
declared "throw()", in which case the compiler always checks the return value
even without this option.  In all other cases, when "operator new" has a
non-empty exception specification, memory exhaustion is signalled by throwing
"std::bad_alloc".  See also new (nothrow).

Reply via email to