Re: operator new: reconciling sections 18.4 and 5.3.4(13) of the 2003
standard
On Mar 18, 7:26 pm, forums...@hotmail.com wrote:
On Mar 18, 2:05 pm, James Kanze <james.ka...@gmail.com> wrote:
a) Does the reference to 'allocation function is declared with an
empty-exception specification (15.4), throw()' imply items '///3' and
'///4' as shown above?
Yes.
First things first, thanks for the clarification. Pavel's
response made me semi nervous. A follow up question:
5.3.4(13) talks about an allocation function throwing
std::bad_alloc or returing a null pointer on failure to
allocate storage.
5.3.4 (8) says:
"A new-expression obtains storage for the object by calling an
allocation function (3.7.3.1). If the new expression terminates by
throwing an exception, it may release storage by calling a
deallocation function
(3.7.3.2)."
The new expression does not 'throw' an exception does it? Its
the allocation function that does. 5.3.4(8) more specifically
"new expression terminates by throwing an exception" seems
somewhat misleading to me.
No, but it calls an allocator function and a constructor, either
of which may throw an exception. The wording could possibly be
better, but I think the meaning is clear: if the new expression
is terminated as a result of an expression propagating out of
it, the compiler may generate code which frees the memory. The
exact conditions under which it will call the deallocator
function are specified in =A75.3.4/17.
--
James Kanze