[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: kdelibs/khtml/rendering
From:       Michael Matz <matz () kde ! org>
Date:       2003-04-30 16:10:55
[Download RAW message or body]

Hi,

On Thu, 17 Apr 2003, Luis Pedro Coelho wrote:

> > > > -    void* operator new(size_t sz, RenderArena* renderArena);
> > > > +    void* operator new(size_t sz, RenderArena* renderArena) throw();
> > >
> > > "No throw guarantee" on operator new ? Are you sure about that one?
> >
> > Of course it's possible to have nothrow() new's.  You would have to
> > explicitely check the return values for being NULL, if you use those,
> > _and_ want to be sure to not become hit by segfaults.
>
> I think it is not as obvious as that. Are you confusing operator new
> with the new operator aka new expression

No.

> (this is not a joke, "operator new" is a function which called by the
> "new" operator)?

"operator new" is a so called allocation function, and those are called by
new expressions.  I have been a bit imprecise, though.  What can be
declared non-throwing are the allocation functions.  You can also replace
the global "::operator new(size_t) throw(bad_alloc);", but are not allowed
to change it's throwing set, which means, that the only non-throwing
allocation functions can be in-class new's or placement new functions.

> Which states that a replacement for ::operator new(size_t) may not return 0,

That's true, it must throw std::bad_alloc if it can't alloc anything.

> but it implies a class specific one may do so.

Or any other allocation functions with a different signature.

And if such a function is called by any new expression, and the function
returns NULL, then initialization shall not take place.  This is not an
issue if the "::operator new(size_t)" is choosen.  The relevant quote from
ISO-C++:

5.3.4 #13:
[Note: unless an allocation function is declared with an empty
exceptionspecification (15.4), throw(), it indicates failure to allocate
storage by throwing a bad_alloc exception (clause 15, 18.4.2.1); it
returns a nonnull pointer otherwise. If the allocation function is
declared with an empty exceptionspecification,throw(), it returns null to
indicate failure to allocate storage and a nonnull pointer otherwise. ] If
the allocation function returns null, initialization shall not be done,
the deallocation function shall not be called, and the value of the
newexpression shall be null.


Ciao,
Michael.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic