According to https://isocpp.org/wiki/faq/freestore-mgmt#new-never-returns-null and https://en.cppreference.com/w/cpp/memory/new/operator_new, a new operator that throws an exception should not return null.
This D20677 breaks that convention with -fno-exceptions.
I noticed the C++ standard doesn't mention such a convention under using -fno-exceptions. I'm new to the C++ standard library, so please let me know if I'm missing something.
But this patch breaks another convention.
- Called by the non-throwing non-array new-expressions. The standard library implementation calls the version (1) and returns a null pointer on failure instead of propagating the exception.
I am submitting another candidate. (Mark the void* operator new ( std::size_t count ) as noexcept?)
If there are no relevant standards, are these the possible ways?
The current patch (Don't call the throwing function).This broken the standard.- Mark the void* operator new ( std::size_t count ) as noexcept.
- Return the -1 in the throwing function? (Too tricky).
- Remove the throwing function declaration (Breaking many api).
- Revert D20677. Because the standard requires that exceptions be thrown.
I really dislike std::__libcpp_unreachable since it just results in undefined behaviour. Either we should do nothing or assert(false);.