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: C++: operator new and disabled exceptions


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.



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