This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++: operator new and disabled exceptions
- From: "Richard Li" <richardpku at gmail dot com>
- To: "Christophe LYON" <christophe dot lyon at st dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 27 Sep 2007 21:31:02 +0800
- Subject: Re: C++: operator new and disabled exceptions
- References: <46FBAC8D.1050507@st.com>
Hi,
I tried to redefine the global "new" operator like the following code,
and it seems to work.
#include <new>
void * operator new (size_t n)
{
return operator new (n, std::nothrow);
}
void * operator new [] (size_t n)
{
return operator new [] (n, std::nothrow);
}
On 9/27/07, Christophe LYON <christophe.lyon@st.com> wrote:
> Hello,
>
> I am compiling a C++ application, which uses the 'new' operator, with
> exceptions disabled (-fno-exceptions).
>
> Yet, the new operator called is the one that throws an exception in case
> of failure. Why is it so ? Isn't it inconsistent with the
> -fno-exceptions flag?
>
> I imagined that compiling with -fno-exceptions would make the compiler
> generate calls to new(nothrow) instead.
>
> In my case, replacing all calls to new to new(nothrow) in the
> application is not an option.
>
> Thanks,
>
> Christophe.
>
>