[PATCH] Fix PR c++/28253: ICE with invalid covariant return

Simon Martin simartin@users.sourceforge.net
Thu Mar 1 20:25:00 GMT 2007


Hi all.

The following invalid code currently triggers an ICE:

=== cut here ===
struct A
{
  virtual A* foo();
};

struct B : virtual A
{
  virtual B* foo();
};

struct C : B
{
  virtual C& foo();
};
=== cut here ===

The fact that C& and B* are not covariant is reported, but an assertion fails 
afterwards in 'update_vtable_entry_for_fn'. What this assertion basically 
says is that if an overrider 'o' for a function 'f' does not have a covariant 
return type or is invalid, then 'f' must not be a thunk.

This is not the case in this example with 'f = B::foo' and 'o = C::foo': 'o' 
is an invalid overrider and 'f' is a thunk because it is an overrider of 
A::foo with a covariant return type. The assertion therefore fails.

The attached patch fixes this by modifying the assertion so that it does not 
fail in cases when 'o' is an invalid overrider for 'f' (another solution 
would be to leave as soon as we know that we're dealing with an invalid 
overrider).

This has been successfully regtested on i686-pc-linux-gnu. Is it OK?

Thanks in advance,
Simon

:ADDPATCH c++:
-------------- next part --------------
2007-03-01  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28253
	* class.c (update_vtable_entry_for_fn): Properly handle invalid overriders
	for thunks.
-------------- next part --------------
Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c	(revision 122410)
+++ gcc/cp/class.c	(working copy)
@@ -2097,7 +2097,8 @@ update_vtable_entry_for_fn (tree t, tree
 				   fixed_offset, virtual_offset);
     }
   else
-    gcc_assert (!DECL_THUNK_P (fn));
+    gcc_assert (DECL_INVALID_OVERRIDER_P (overrider_target) ||
+		!DECL_THUNK_P (fn));
 
   /* Assume that we will produce a thunk that convert all the way to
      the final overrider, and not to an intermediate virtual base.  */
-------------- next part --------------
2007-03-01  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28253
	* g++.dg/inherit/covariant16.C: New test.
-------------- next part --------------
/* PR c++/28253 This used to ICE. */
/* { dg-do "compile" } */

struct A
{
  virtual A* foo();
};

struct B : virtual A
{
  virtual B* foo(); /* { dg-error "overriding" } */
};

struct C : B
{
  virtual C& foo(); /* { dg-error "conflicting return type" } */
};


More information about the Gcc-patches mailing list