From: Jakub Jelinek Date: Mon, 25 Jun 2018 17:39:55 +0000 (+0200) Subject: backport: re PR c++/85068 (ICE with invalid covariant return type hierarchy) X-Git-Tag: releases/gcc-6.5.0~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a775eeb61c4fcee6859087625d0277fadc3baa9;p=thirdparty%2Fgcc.git backport: re PR c++/85068 (ICE with invalid covariant return type hierarchy) Backported from mainline 2018-03-27 Jakub Jelinek PR c++/85068 * class.c (update_vtable_entry_for_fn): Don't ICE if base_binfo is NULL. Assert if thunk_binfo is NULL then errorcount is non-zero. * g++.dg/inherit/covariant22.C: New test. From-SVN: r262086 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c831f14f09c4..92171f91b911 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,12 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-27 Jakub Jelinek + + PR c++/85068 + * class.c (update_vtable_entry_for_fn): Don't ICE if base_binfo + is NULL. Assert if thunk_binfo is NULL then errorcount is non-zero. + 2018-03-16 Jakub Jelinek PR c++/84874 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 86e7e003fe49..6de0421d6dc6 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2669,19 +2669,20 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals, order. Of course it is lame that we have to repeat the search here anyway -- we should really be caching pieces of the vtable and avoiding this repeated work. */ - tree thunk_binfo, base_binfo; + tree thunk_binfo = NULL_TREE; + tree base_binfo = TYPE_BINFO (base_return); /* Find the base binfo within the overriding function's return type. We will always find a thunk_binfo, except when the covariancy is invalid (which we will have already diagnosed). */ - for (base_binfo = TYPE_BINFO (base_return), - thunk_binfo = TYPE_BINFO (over_return); - thunk_binfo; - thunk_binfo = TREE_CHAIN (thunk_binfo)) - if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo), - BINFO_TYPE (base_binfo))) - break; + if (base_binfo) + for (thunk_binfo = TYPE_BINFO (over_return); thunk_binfo; + thunk_binfo = TREE_CHAIN (thunk_binfo)) + if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo), + BINFO_TYPE (base_binfo))) + break; + gcc_assert (thunk_binfo || errorcount); /* See if virtual inheritance is involved. */ for (virtual_offset = thunk_binfo; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8fcb4c316c9e..3eef4e304fb5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-27 Jakub Jelinek + + PR c++/85068 + * g++.dg/inherit/covariant22.C: New test. + 2018-03-23 Jakub Jelinek PR inline-asm/85034 diff --git a/gcc/testsuite/g++.dg/inherit/covariant22.C b/gcc/testsuite/g++.dg/inherit/covariant22.C new file mode 100644 index 000000000000..26c96e6abfc6 --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/covariant22.C @@ -0,0 +1,19 @@ +// PR c++/85068 +// { dg-do compile } + +struct A; + +struct B +{ + virtual A *foo (); // { dg-error "overriding" } +}; + +struct C : virtual B +{ + virtual C *foo (); // { dg-error "invalid covariant return type for" } +}; + +struct D : C +{ + virtual C *foo (); +};