[tree-ssa] Fun with exceptions -- opinions needed
Fergus Henderson
fjh@cs.mu.OZ.AU
Tue Jun 17 10:08:00 GMT 2003
On 16-Jun-2003, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On 16 Jun 2003, Frank Ch. Eigler wrote:
>
> > > [...] OK. So think about what happens if "get" throws an exception
> > > in the statement "i = get (strm.5)". Right, the side effect of
> > > assigning a new value to "i" does not happen.
> >
> > Can someone explain why such a side-effect would be expected?
>
> In "l = rhs", where rhs is (or contains) a function call, there is a
> sequence point right after the copying of the return value (1.9.17).
Agreed. But that means copying the return value from the expression
in the "return" statement inside the function body to an unnamed
temporary object which holds the value of the rhs function call.
It does not mean after copying the return value to the lhs of the assignment.
> This means, that in C++ function calls can clobber the return value, even
> when they throw,
In "l = rhs", "l" is not the return value.
> Now that I think about this, some of our C++
> testcases could be wrong, for instance
>
> int i_throw_something ( throw 1; return 42; }
> void bla() {
> int i = 0;
> try { i = i_throw_something(); }
> catch (...) {/*ignore*/}
> if (i != 0)
> abort();
> }
No, that test case is correct. "When an exception is thrown, control
is transferred to the nearest handler with a matching type" (C++98 15.1
paragraph 3). The statement "return 42" never gets executed.
The assignment to `i' never gets executed.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
More information about the Gcc
mailing list