I have the following declaration:
void * operator new (size_t s, PersistentMemory * m) throw() {return m->allocatePersistentMemory(s);}
I test running out of memory at startup, which results in m->allocatePersistentMemory(s); 0. The new then calls the null pointer constructor for this
However, based on 3.7.3.1 paragraph 3 of the C ++ 2003 standard:
A distribution function that cannot allocate storage can call currently set new_handler (18.4.2.2), if any. [Note: A software distribution function can get the address of the currently set new_handler using the set_new_handler function (18.4.2.3). ] If the distribution function is declared with an empty specification exception (15.4), throw () does not allow allocating storage, this should return a null pointer. Any other distribution function that does not work for storage distribution is indicated only by a failure, throwing an exception to the std :: bad_alloc class (18.4.2.1) or a class derived from std :: bad_alloc.
The way I understand it is that if m->allocatePersistentMemory(s) return null should lead to returning the whole operator new() throw() null without calling the constructor. Am I missing some other condition elsewhere that cancels this?
Thanks!
source share