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++
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Aldy Hernandez <aldyh at redhat dot com>
- Cc: Richard Henderson <rth at redhat dot com>, <gcc-patches at gcc dot gnu dot org>, <jakub at redhat dot com>, <jason at redhat dot com>
- Date: Wed, 6 Nov 2002 19:22:33 +0000 (GMT)
- Subject: Re: [basic-improvements] try/finally support for c/c++
On Wed, 6 Nov 2002, Aldy Hernandez wrote:
> > > + containing one or statements, and a @code{__finally} block contatining
> > > + one or more statements. The @code{__finally} block will execute after
> > > + the @code{__try} block but before the code following the
> > > + @code{__try/__finally} construct, even if the @code{__try} block exits
> > > + the current function.
> >
> > There should be a corresponding mention of longjmp to that in the formal
> > edits.
>
> I don't understand what you want here. Could you elaborate please?
It must be made clear in the user docs that exiting via longjmp yields
undefined behavior, rather than the finally block executing before longjmp
goes to its destination.
> Joseph, how does this one look?
You still need to make the jumps that aren't permitted into constraint
violations (with corresponding testcases for the diagnostics) except for
longjmp and computed goto cases (undefined behavior at runtime).
I don't think it's yet been stated whether you may jump into the finally
block from outside, or what happens after the execution of the finally
block if you do.
> + If a try block was exited by @code{return}, then the function returns
> + after finishing the finally block (unless inside other try block). If
> + a try block is exited normally, then execution continues after the end
> + of the finally block. If a try block is exited through an exception
> + being thrown (or forced unwinding), then after finally block exits,
> + the exception is resumed or forced unwinding continues.
This paragraph fails to mention what happens if the try block is exited by
a jump (goto, break or continue).
Whichever cases of computed goto are defined / undefined need to be
documented.
> + A @code{goto}, @code{break}, @code{return}, or @code{continue}
> + statement can be used to transfer control out of a try block but not
> + into one. Also, a @code{longjmp} may not be used to transfer control
> + into a try or finally block. If done, the behavior is undefined.
You need to include @code{switch} in the statements that aren't permitted
to transfer control into a try block. Wasn't it intended that longjmp
can't jump out either?
(Note: I'm not examining the C++98 edits, there may be similar issues
there.)
--
Joseph S. Myers
jsm28@cam.ac.uk