From 2c1fb3eefdae087e7990b952563fd519d4736633 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 28 Feb 2011 16:41:21 -0500 Subject: [PATCH] re PR c++/47873 (virtual Inheritance - Covariant Virtual Function - Segfault) PR c++/47873 * class.c (update_vtable_entry_for_fn): Check BINFO_LOST_PRIMARY_P after checking for a non-thunk. From-SVN: r170576 --- gcc/cp/ChangeLog | 6 ++++ gcc/cp/class.c | 4 +-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/g++.dg/inherit/covariant18.C | 41 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/inherit/covariant18.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 50e4b48d5ea..d1b1b4aaf4e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-02-28 Jason Merrill + + PR c++/47873 + * class.c (update_vtable_entry_for_fn): Check BINFO_LOST_PRIMARY_P + after checking for a non-thunk. + 2011-02-26 Jason Merrill PR c++/47904 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 0d485fc6ac7..1325260f51e 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2250,10 +2250,10 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals, { tree main_binfo = TYPE_BINFO (BINFO_TYPE (b)); tree bv = chain_index (ix, BINFO_VIRTUALS (main_binfo)); - if (BINFO_LOST_PRIMARY_P (b)) - lost = true; if (!DECL_THUNK_P (TREE_VALUE (bv))) break; + if (BINFO_LOST_PRIMARY_P (b)) + lost = true; } first_defn = b; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 10c430a3c88..fc2ad4fd02c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-02-28 Jason Merrill + + * g++.dg/inherit/covariant18.C: New. + 2011-02-28 Jakub Jelinek PR middle-end/47893 diff --git a/gcc/testsuite/g++.dg/inherit/covariant18.C b/gcc/testsuite/g++.dg/inherit/covariant18.C new file mode 100644 index 00000000000..31e62165e7c --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/covariant18.C @@ -0,0 +1,41 @@ +// PR c++/47873 +// { dg-do run } + +struct Base +{ + virtual ~Base(){} + + virtual Base& This() { return *this; } +}; + + +struct Ent : virtual Base +{ + void *m_Body; + + Ent& This() { return *this; } + + virtual Ent& body() + { + return This(); + } + +}; + + +struct Msg : virtual Ent +{ + Msg() + { + body(); + } + + Msg& This() { return *this; } +}; + +int main() +{ + Msg m; + + return 0; +} -- 2.30.2