re PR c++/85068 (ICE with invalid covariant return type hierarchy)
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Mar 2018 11:02:08 +0000 (13:02 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 27 Mar 2018 11:02:08 +0000 (13:02 +0200)
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: r258873

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/inherit/covariant22.C [new file with mode: 0644]

index 654e608c6b5e864ab9df854eb4c824e32dc74d18..1f035c30daca99b0b2f39723941b17267014992b 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-27  Jakub Jelinek  <jakub@redhat.com>
+
+       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-27  Paolo Carlini  <paolo.carlini@oracle.com>
            Jason Merrill  <jason@redhat.com>
 
index 3edae0f5e6193eced5df8bf7b75082d54086c960..debcaf21cf76393dd92f2122111beff672339f8c 100644 (file)
@@ -2479,19 +2479,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;
index be30a45ebe807bb25051bf4471b72d59b5e1687a..1bce088faf32e043f077fceee61a3c7fe0ce15e2 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/85068
+       * g++.dg/inherit/covariant22.C: New test.
+
 2018-03-27  Richard Biener  <rguenther@suse.de>
 
        PR testsuite/84004
diff --git a/gcc/testsuite/g++.dg/inherit/covariant22.C b/gcc/testsuite/g++.dg/inherit/covariant22.C
new file mode 100644 (file)
index 0000000..26c96e6
--- /dev/null
@@ -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 ();
+};