This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New and exception


On Jul 12, 2002, Tim Hollebeek <tim@hollebeek.com> wrote:

> On Fri, Jul 12, 2002 at 04:12:01PM -0300, Alexandre Oliva wrote:
>> On Jul 12, 2002, "H. J. Lu" <hjl@lucon.org> wrote:
>> 
>> > When I use -fno-exceptions, I can be prepared to deal any returns from
>> > new as long as it doesn't throw an exception
>> 
>> That's hardly possible, unless you're using new as a shorthand for
>> malloc.  new often calls ctors, and there's no way you can interpose a
>> NULL-test between the return from operator new and the ctor call.

> "no way" ... EXCEPT by calling new (std::nothrow) instead of new, as
> he suggested.  Be quite a bit more careful about what you claim is
> impossible.

Point is the program must be modified to cope with the possibility of
new returning NULL, so why not go ahead and change it so as to call
the nothrow version?  And it's not just a matter of GCC's modifying
the code so as to call operator new(nothrow) (which is what H.J.Lu had
suggested), it must also modify the code it generates for the entire
new construct to check for a NULL return value and bypass the ctor
call.  I can see how it could be useful to do the latter, but I still
think that, if you're modifying the program to cope with NULL anyway,
putting in some NOTHROW preprocessor macros that expand to the
appropriate magic depending on the compiler in use is no big deal.
Perhaps I'm oversimplifying this matter?

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]