This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[c++patch] PR#7
- To: gcc-patches at gcc dot gnu dot org
- Subject: [c++patch] PR#7
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Wed, 08 Mar 2000 15:46:44 +0000
- Organization: CodeSourcery, LLC
Hi,
here's a patch for PR#7 concerning a seg fault on catching a virtually
derived object.
Although we correctly freed the original pointer, we didn't destruct it.
I'm going to stick the testcase in as g++.bugs/pr7.C, unless anyone
objects.
ok?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-03-08 Nathan Sidwell <nathan@codesourcery.com>
* exception.cc (__cp_pop_exception): Cleanup the original object.
Index: cp/exception.cc
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/exception.cc,v
retrieving revision 1.29
diff -c -3 -p -r1.29 exception.cc
*** exception.cc 2000/02/26 20:15:45 1.29
--- exception.cc 2000/03/08 15:13:59
*************** __cp_pop_exception (cp_eh_info *p)
*** 252,261 ****
if (p->cleanup)
/* 2 is a magic value for destructors; see build_delete(). */
! p->cleanup (p->value, 2);
if (! __is_pointer (p->type))
! __eh_free (p->original_value); // value may have been co-erced.
__eh_free (p);
}
--- 252,261 ----
if (p->cleanup)
/* 2 is a magic value for destructors; see build_delete(). */
! p->cleanup (p->original_value, 2); // value may have been adjusted.
if (! __is_pointer (p->type))
! __eh_free (p->original_value); // value may have been adjusted.
__eh_free (p);
}
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 8 Mar 2000 <nathan@codesourcery.com>
// Derived from PR#7
// We need to destroy the thrown object when exiting the catch
// clause. That needs to destroy the original thrown object, not
// the caught one (which might be a base).
static int ok = 0;
struct A
{
A (){};
virtual ~A () {};
};
struct B : virtual A
{
int value;
B ()
:value(10)
{}
~B()
{
if (value == 10)
ok = 1;
}
};
int main()
{
try {
throw B ();
} catch (A & e) {
}
return !ok;
}