This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c++/27492: ICE on invalid covariant return type


Hi all.

The following invalid snippet causes an ICE on mainline:

=== cut here ===
struct A {};

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

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

C* C::foo() { return 0; }

struct D : C {};
=== cut here ===

The fact that C::foo is not a valid overrider of B::foo is properly detected 
when parsing its declaration; DECL_INVALID_OVERRIDER_P is therefore set to 1. 
However, this property is not propagated to the definition for C::foo when
both trees are merged in 'duplicate_decls'.

When we finish to build D, C::foo is therefore not considered as an invalid 
overrider, which triggers an ICE in cp/method.c:129.

The attached patch fixes this by ensuring that the DECL_INVALID_OVERRIDER_P 
property for functions decls is properly handled in 'duplicate_decls'.

I have successfully regtested this on i686-pc-linux-gnu. Is it OK?

Thanks in advance,
Simon

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

	PR c++/27492
	* decl.c (duplicate_decls): Don't reset DECL_INVALID_OVERRIDER_P for
	function decls.
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 120735)
+++ gcc/cp/decl.c	(working copy)
@@ -1576,6 +1576,7 @@ duplicate_decls (tree newdecl, tree oldd
       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
+      DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
       if (DECL_OVERLOADED_OPERATOR_P (olddecl) != ERROR_MARK)
 	SET_OVERLOADED_OPERATOR_CODE
2007-01-12  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/27492
	* g++.dg/inherit/covariant15.C: New test.
/* This used to ICE (PR c++/27492) */
/* { dg-do "compile" } */

struct A {};

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

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

C* C::foo() { return 0; }

struct D : C {};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]