This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [basic-improvements] try/finally support for c/c++ - more tests
- From: Richard Henderson <rth at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Aldy Hernandez <aldyh at redhat dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "jason at redhat dot com" <jason at redhat dot com>
- Date: Wed, 6 Nov 2002 16:03:07 -0800
- Subject: Re: [basic-improvements] try/finally support for c/c++ - more tests
- References: <20021106124304.G10988@devserv.devel.redhat.com> <8450000.1036625540@warlock.codesourcery.com>
On Wed, Nov 06, 2002 at 03:32:20PM -0800, Mark Mitchell wrote:
> There is nothing you can do with try/finally in C++ you can't already
> do:
>
> try { X } finally { Y }
>
> can always be replaced with either of:
>
> (1) try { X } catch (...) { Y; throw; } Y;
>
> or:
>
> (2) { struct S { ~S() { Y } } s; X }
>
> depending on your stylistic preference.
True. I was simply trying to make things easier for the
thread library in having one macro work for both languages.
> I do not think we should add exception support of any kind to GNU C; use
> C++ if you want exceptions.
See elsewhere about resistance compiling libc with a c++ compiler.
The main problem is that you simply cannot implement cleanups with
a few calls to a runtime library. There are data structures that
the compiler must set up related to how it generated code.
> If we do want to check these patches in, the semantics should be given
> in terms of translation to (1) above.
I don't agree with this.
The EH ABI clearly distingishes between cleanups and catches.
Thus the semantics are exactly those of (2), and not those of
(1) at all. Indeed, even ISO C++ makes this distinction with
std::uncaught_exception.
Further, try/catch/rethrow does not express what happens when
you use goto/break/continue/return to leave the try block.
r~