This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: use of exceptions in GCC
- From: "lhmouse"<lh_mouse at 126 dot com>
- To: "Martin Sebor"<msebor at gmail dot com>, "GCC Mailing List"<gcc at gcc dot gnu dot org>
- Date: Thu, 17 Nov 2016 11:58:41 +0800
- Subject: Re: use of exceptions in GCC
- Authentication-results: sourceware.org; auth=none
- References: <828fcea0-6caf-2914-b18b-0977778d9e9e@gmail.com>
> GCC is built with -fno-exceptions. I assume that's mainly to avoid
> having to catch and handle exceptions in what was originally C code.
> I also assume that also means that there's a policy or convention in
> place against throwing exceptions in GCC or making use of constructs
> that might throw (such as the non-placement new expressions).
It also drops the need of _runtime type info_ (a.k.a. RTTI) and stack unwind
table, reducing the size of binary files.
>
> By coincidence, bootstrapping my patch for bugs 77531 and 78284
> exposed a few uses of the non-placement array new expression in
> dominance.c (in dom_info::dom_init) that may throw an exception(*).
>
> I'm wondering if those calls should be changed to avoid exceptions.
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.
>
> I'm also curious if there really is a policy/convention for dealing
> with exceptions in GCC, what it actually is/says.
Compilers aren't envisioned to be long-running programs, so aborting
on unexpected conditions is reasonable. This isn't only the case for GCC,
but also LLVM.
>
> Thanks
> Martin
>
> [*] My patch exposed these because when -fno-exceptions is used
> (and coincidentally also in C++ 98 mode) GCC emits conditional calls
> to operator new[](SIZE_MAX) when the size computation that multiplies
> the number of elements by the element size exceeds SIZE_MAX. The
> -Walloc-size-larger-than warning flags for attempting to allocate
> more storage than the size of the biggest object, or SIZE_MAX / 2.
------------------
Best regards,
lh_mouse
2016-11-17