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: use of exceptions in GCC


On 17 November 2016 at 03:58, lhmouse wrote:
> If a program is compiled with `-fno-exceptions` and an exception
> will have been thrown otherwise, `std::abort()` (or an equivalent such as
> `__builtin_trap()`) is called. This preserves the semantical correctness
> of not checking the value of a throwing new expression,
> since it can't return a null pointer.

$ g++ -fno-exceptions -include new -x c++ -  <<< 'int main() { new
char[std::size_t(-1)]; }'
$ ./a.out
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

Compiling the program with -fno-exceptions doesn't change whether
operator new throws or aborts, because the definition is part of the
runtime, which is compiled separately from the program. When libstdc++
is built with -fno-exceptions then operator new will abort instead of
throw, but that's a different condition from compiling the program
with -fno-excetions.


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