This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to setup_vtbl_ptr
- From: Jason Merrill <jason at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 12 Dec 2001 17:55:44 +0000
- Subject: C++ PATCH to setup_vtbl_ptr
Some of the functions-as-trees reorganization broke vtable setup for
destructors, as we no longer call setup_vtbl_ptr when instantiating
non-constructors. This patch fixes that by always pushing a
CTOR_INITIALIZER when in a template. The name could probably be improved,
but it has precisely the semantics we want. Testcase attached.
Tested i686-pc-linux-gnu on the 3.0 branch. Mark, this is a regression
from 2.95; is the patch OK for 3.0.3?
2001-12-12 Jason Merrill <jason@redhat.com>
* semantics.c (setup_vtbl_ptr): Always build a CTOR_INITIALIZER
if we're in a template.
*** semantics.c.~1~ Mon Jul 16 21:16:10 2001
--- semantics.c Wed Dec 12 15:45:08 2001
*************** setup_vtbl_ptr (member_init_list, base_i
*** 1182,1208 ****
if (vtbls_set_up_p)
return;
! if (DECL_CONSTRUCTOR_P (current_function_decl))
{
! if (processing_template_decl)
! add_stmt (build_min_nt
! (CTOR_INITIALIZER,
! member_init_list, base_init_list));
! else
! {
! tree ctor_stmt;
! /* Mark the beginning of the constructor. */
! ctor_stmt = build_stmt (CTOR_STMT);
! CTOR_BEGIN_P (ctor_stmt) = 1;
! add_stmt (ctor_stmt);
! /* And actually initialize the base-classes and members. */
! emit_base_init (member_init_list, base_init_list);
! }
}
! else if (DECL_DESTRUCTOR_P (current_function_decl)
! && !processing_template_decl)
{
tree if_stmt;
tree compound_stmt;
--- 1182,1203 ----
if (vtbls_set_up_p)
return;
! if (processing_template_decl)
! add_stmt (build_min_nt (CTOR_INITIALIZER,
! member_init_list, base_init_list));
! else if (DECL_CONSTRUCTOR_P (current_function_decl))
{
! tree ctor_stmt;
! /* Mark the beginning of the constructor. */
! ctor_stmt = build_stmt (CTOR_STMT);
! CTOR_BEGIN_P (ctor_stmt) = 1;
! add_stmt (ctor_stmt);
! /* And actually initialize the base-classes and members. */
! emit_base_init (member_init_list, base_init_list);
}
! else if (DECL_DESTRUCTOR_P (current_function_decl))
{
tree if_stmt;
tree compound_stmt;
// Test that vtables are set up properly for constructors and destructors
// of template classes.
// { dg-do run }
int r;
template <class T>
struct A {
virtual void f () { }
A() { f (); }
~A() { f (); }
};
struct B : public A<int> {
virtual void f () { ++r; }
};
int main ()
{
{ B b; }
return r;
}