[basic-improvements] try/finally support for c/c++ - more tests

Richard Henderson rth@redhat.com
Wed Nov 6 16:03:00 GMT 2002


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~



More information about the Gcc-patches mailing list