This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ PATCH to build_throw


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++;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]