This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH to build_throw
- To: Jason Merrill <jason_merrill at redhat dot com>
- Subject: Re: C++ PATCH to build_throw
- From: Richard Henderson <rth at redhat dot com>
- Date: Mon, 23 Apr 2001 13:50:21 -0700
- Cc: gcc-patches at gcc dot gnu dot org
- References: <m3k84cv6vv.fsf@prospero.cambridge.redhat.com>
On Mon, Apr 23, 2001 at 12:42:28AM +0100, Jason Merrill wrote:
> The C++ standard says that if an exception is thrown between the evaluation
> of the expression to be thrown and it being caught, terminate() is called.
Correct, but before the expression is completely evaluated, a new
exception may be substituted. For instance,
struct A
{
A () { throw 1; }
A (const A&) { }
};
should free the exception object we allocated for "throw a" in main
and propagate the "1". What do you think of the following test?
I do see however that I had my try/cleanup block around the wrong
expression. Oops.
r~
// Test that an exception thrown out of the (non copy) constructor for
// the object (i.e. "before completing evaluation of the expression to
// be thrown") cleans up the allocated memory and propagates the correct
// expression.
extern "C" void abort ();
struct A
{
A ();
A (const A&);
};
static int freed;
int main (void)
{
try
{
throw A();
}
catch (int i)
{
if (i == 1 && freed == 1)
return 0;
}
catch (...)
{
}
abort ();
}
A::A () { throw 1; }
A::A (const A&) { }
extern "C" void __cxa_free_exception(void *);
static void __cxa_free_exception(void *)
{
freed++;
}