re PR c++/20232 (ICE with covariancy)
authorNathan Sidwell <nathan@codesourcery.com>
Tue, 1 Mar 2005 09:57:45 +0000 (09:57 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 1 Mar 2005 09:57:45 +0000 (09:57 +0000)
cp:
PR c++/20232
* class.c (update_vtable_entry_for_fn): Don't crash on invalid
covariancy.

* cp-tree.g (THUNK_TARGET): Expand comment.
* method.c (use_thunk): Make sure we also use the target, if that
is a thunk.
testsuite:
PR c++/20232
* g++.dg/inherit/covariant12.C: New.

From-SVN: r95733

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/inherit/covariant12.C [new file with mode: 0644]

index 36e29ce306f185d0c77a9648b347eedd6929d9d9..51cc4f1bffe42b2cc14b829f0dcc370b33707a13 100644 (file)
@@ -1,3 +1,13 @@
+2005-03-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/20232
+       * class.c (update_vtable_entry_for_fn): Don't crash on invalid
+       covariancy. 
+
+       * cp-tree.g (THUNK_TARGET): Expand comment.
+       * method.c (use_thunk): Make sure we also use the target, if that
+       is a thunk.
+
 2005-02-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/20206
index f6ba914cb84e4335adc6ff340c6f2208937141a7..ba89ea146ed47eb854a243f230f4e1298a3f4295 100644 (file)
@@ -2048,14 +2048,17 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
          tree thunk_binfo, base_binfo;
 
          /* Find the base binfo within the overriding function's
-            return type.  */
+            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);
-              !SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
-                                  BINFO_TYPE (base_binfo));
+              thunk_binfo;
               thunk_binfo = TREE_CHAIN (thunk_binfo))
-           continue;
-
+           if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
+                                  BINFO_TYPE (base_binfo)))
+             break;
+         
          /* See if virtual inheritance is involved.  */
          for (virtual_offset = thunk_binfo;
               virtual_offset;
@@ -2063,7 +2066,8 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
            if (BINFO_VIRTUAL_P (virtual_offset))
              break;
          
-         if (virtual_offset || !BINFO_OFFSET_ZEROP (thunk_binfo))
+         if (virtual_offset
+             || (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
            {
              tree offset = convert (ssizetype, BINFO_OFFSET (thunk_binfo));
 
index caac8b24fb6d6898045fc40e0d68b077abd4f8cd..d7144242d6d91a3183e60aab0b6aa30e1ddfa4fa 100644 (file)
@@ -2913,7 +2913,8 @@ struct lang_decl GTY(())
 #define THUNK_ALIAS(DECL) \
   (DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (DECL))->decl_flags.u.template_info)
 
-/* For thunk NODE, this is the FUNCTION_DECL thunked to.  */
+/* For thunk NODE, this is the FUNCTION_DECL thunked to.  It is
+   possible for the target to be a thunk too.  */
 #define THUNK_TARGET(NODE)                             \
   (DECL_LANG_SPECIFIC (NODE)->u.f.befriending_classes)
 
index 85e2b3f8787d05eb2ef011cab22e0d882e2bf949..7a99c26247109add571e424136a3feb7b7302fbc 100644 (file)
@@ -328,6 +328,10 @@ use_thunk (tree thunk_fndecl, bool emit_p)
        There's no need to process this thunk again.  */
     return;
 
+  if (DECL_THUNK_P (function))
+    /* The target is itself a thunk, process it now.  */
+    use_thunk (function, emit_p);
+  
   /* Thunks are always addressable; they only appear in vtables.  */
   TREE_ADDRESSABLE (thunk_fndecl) = 1;
 
index 26fa08c5ce8a79358a576d45e07787db11ff6129..5e3ceaa2078c78f08cba298d180367fee1d793db 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/20232
+       * g++.dg/inherit/covariant12.C: New.
+
 2005-02-28  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/19479
diff --git a/gcc/testsuite/g++.dg/inherit/covariant12.C b/gcc/testsuite/g++.dg/inherit/covariant12.C
new file mode 100644 (file)
index 0000000..434082a
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) 2004 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 27 Feb 2005<nathan@codesourcery.com>
+
+// PR 20232: ICE on invalid
+
+struct T { };
+
+struct S;
+
+struct B
+{
+  virtual T *Foo (); // { dg-error "overriding" "" }
+};
+
+struct D : B
+{
+  virtual S *Foo (); // { dg-error "invalid covariant" "" }
+};