[patch] Fix PR c++/22604, ICE after invalid covariant return
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Fri Aug 5 20:53:00 GMT 2005
Consider the following testcase:
struct A;
struct B
{
virtual A* foo(); // { dg-error "overriding" }
};
struct C : B
{
virtual C* foo(); // { dg-error "invalid covariant" }
};
The declaration of foo in struct C is invalid.
When updating the vtable for C the compiler fails to check for invalid
overriders in update_vtable_entry_for_fn, thus causing an ICE.
The attached patch adds the missing check and the above testcase.
In addition the patch allows us to squeeze more errors out of
g++.old-deja/g++.mike/p811.C.
Bootstrapped and regtested on i686-pc-linux-gnu.
OK for mainline and 4.0 branch (since this is a regression)?
Regards,
Volker
2005-08-05 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/22604
* class.c (update_vtable_entry_for_fn): Check for invalid overrider.
===================================================================
--- gcc/gcc/cp/class.c 1 Aug 2005 04:02:23 -0000 1.730
+++ gcc/gcc/cp/class.c 5 Aug 2005 14:50:53 -0000
@@ -1972,6 +1972,8 @@ update_vtable_entry_for_fn (tree t, tree
if (overrider == error_mark_node)
return;
overrider_target = overrider_fn = TREE_PURPOSE (overrider);
+ if (DECL_INVALID_OVERRIDER_P (overrider_target))
+ return;
/* Check for adjusting covariant return types. */
over_return = TREE_TYPE (TREE_TYPE (overrider_target));
===================================================================
2005-08-05 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/22604
* g++.dg/inherit/covariant14.C: New test.
* g++.old-deja/g++.mike/p811.C: Add more error markers.
===================================================================
--- gcc/gcc/testsuite/g++.dg/inherit/covariant14.C 2005-06-27 13:32:40.055820328 +0200
+++ gcc/gcc/testsuite/g++.dg/inherit/covariant14.C 2005-08-05 17:12:40.000000000 +0200
@@ -0,0 +1,16 @@
+// PR c++/22604
+// ICE on invalid overrider for virtual function
+// Origin: Flash Sheridan <flash@pobox.com>
+// { dg-do compile }
+
+struct A;
+
+struct B
+{
+ virtual A* foo(); // { dg-error "overriding" }
+};
+
+struct C : B
+{
+ virtual C* foo(); // { dg-error "invalid covariant" }
+};
===================================================================
--- gcc/gcc/testsuite/g++.old-deja/g++.mike/p811.C 1 Nov 2004 18:24:33 -0000 1.6
+++ gcc/gcc/testsuite/g++.old-deja/g++.mike/p811.C 5 Aug 2005 20:45:53 -0000
@@ -512,10 +512,10 @@ class Y {
public:
Y() {}
virtual const char *stringify() = 0;
- virtual char *stringify2() const = 0; // { dg-error "overriding" }
+ virtual char *stringify2() const = 0; // { dg-error "overriding|virtual" }
};
-class X: public Y {
+class X: public Y { // { dg-error "pure within" }
public:
X(): Y() {}
const char *stringify(); // { dg-error "candidate" }
@@ -536,7 +536,7 @@ X::stringify2() // { dg-error "does no
main()
{
- X x;
+ X x; // { dg-error "abstract" }
Y& y = x;
cout << "x\n";
===================================================================
More information about the Gcc-patches
mailing list