I have the following declaration:
void * operator new (size_t s, PersistentMemory * m) throw()
{return m->allocatePersistentMemory(s);}
I'm testing memory exhaustion on start-up, which results in m->allocatePersistentMemory(s);
returning 0. New then calls the constructor with a null pointer for this
However, based on 3.7.3.1 paragraph 3 of C++ 2003 standard:
An allocation function that fails to allocate storage can invoke the currently installed new_handler (18.4.2.2), if any. [Note: A program-supplied allocation function can obtain the address of the currently installed new_handler using the set_new_handler function (18.4.2.3). ] If an allocation function declared with an empty exception-specification (15.4), throw(), fails to allocate storage, it shall return a null pointer. Any other allocation function that fails to allocate storage shall only indicate failure by throwing an exception of class std::bad_alloc (18.4.2.1) or a class derived from std::bad_alloc.
The way I understand things is that having m->allocatePersistentMemory(s)
return null should result in the whole operator new() throw()
returning null without calling the constructor. Am I missing some other condition elsewhere that overrides this?
Thanks!