This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++: operator new and disabled exceptions
- From: Christian BRUEL <christian dot bruel at st dot com>
- To: Christophe LYON <christophe dot lyon at st dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 28 Sep 2007 15:30:47 +0200
- Subject: Re: C++: operator new and disabled exceptions
- References: <46FCF95A.3000200@st.com>
hello,
there is a difference between calling new and new (std::nothrow) from a
fno-exceptions context:
- new (std::nothrow) would return 0 in case of error
- new () would throw std::bad_alloc that would finish in
std::terminate() or abort()
so there is a possible difference in behavior if an -fno-exceptions
application relies on std::terminate().
so if you patch gcc to use the nothrow internally, you would need to
compile all your applications and all your libraries and runtimes with
-fcheck-new.
Christian
Christophe LYON wrote:
Hello,
I have already asked this question on gcc-help (see
http://gcc.gnu.org/ml/gcc-help/2007-09/msg00328.html), but I would like
advice from GCC developers.
Basically, when I compile with -fno-exceptions, I wonder why the G++
compiler still generates calls to the standard new operator (the one
that throws bad_alloc when it runs out of memory), rather than
new(nothrow) (_ZnwjRKSt9nothrow_t) ?
In addition, do you think I can patch my GCC such that it calls
new(nothrow) when compiling with -fno-exceptions, or is it a bad idea?
(compatibility issues, ...)
Thanks for your recommendation,
Christophe.