]> gcc.gnu.org Git - gcc.git/commitdiff
search.c (get_vbase_1): Count only virtual bases.
authorNathan Sidwell <nathan@codesourcery.com>
Fri, 19 Jan 2001 13:32:53 +0000 (13:32 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 19 Jan 2001 13:32:53 +0000 (13:32 +0000)
cp:
* search.c (get_vbase_1): Count only virtual bases.
testsuite:
* g++.old-deja/g++.other/vbase5.C: New test.

From-SVN: r39132

gcc/cp/ChangeLog
gcc/cp/search.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/vbase5.C [new file with mode: 0644]

index b81617e82f4a523b428d78737b5e00c2337da462..b12874f9391b8f800ea4bc1330554d8f02f31d66 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-19  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * search.c (get_vbase_1): Count only virtual bases.
+
 2001-01-19  Nathan Sidwell  <nathan@codesourcery.com>
 
        * class.c (duplicate_tag_error): Robustify flag clearing.
index 5beedb0a6078af84b273f516a113c64092921691..0bb309fa5bded80bc36d69bc428d2259282e1813 100644 (file)
@@ -193,15 +193,15 @@ get_vbase_1 (parent, binfo, depth)
   tree binfos;
   int i, n_baselinks;
   tree rval = NULL_TREE;
+  int virtualp = TREE_VIA_VIRTUAL (binfo) != 0;
 
-  if (BINFO_TYPE (binfo) == parent && TREE_VIA_VIRTUAL (binfo))
+  *depth -= virtualp;
+  if (virtualp && BINFO_TYPE (binfo) == parent)
     {
       *depth = 0;
       return binfo;
     }
 
-  *depth = *depth - 1;
-
   binfos = BINFO_BASETYPES (binfo);
   n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
 
@@ -218,7 +218,7 @@ get_vbase_1 (parent, binfo, depth)
       if (nrval)
        rval = nrval;
     }
-  *depth = *depth+1;
+  *depth += virtualp;
   return rval;
 }
 
index efeee5df66b8d2ece11936a77801b762a513b2f7..b8b57aff7db6685d031b352b609585129a1fa8b3 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-19  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.other/vbase5.C: New test.
+
 2001-01-19  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/execute/20010118-1.c: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/vbase5.C b/gcc/testsuite/g++.old-deja/g++.other/vbase5.C
new file mode 100644 (file)
index 0000000..03b846f
--- /dev/null
@@ -0,0 +1,202 @@
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 19 Jan 2001 <nathan@codesourcery.com>
+
+// Bug 1701. building a vbase path was not using the shortest number of
+// vbases. Normally that's just a pessimization, unfortunately during
+// constructoring it leads to uninitialized reads.
+
+extern "C" int printf (...);
+
+int fail = 0;
+
+/*{{{  struct Base*/
+struct Base
+{
+  unsigned m;
+  static Base *addr;
+  
+  Base ();
+  virtual ~Base ();
+};
+/*}}}*/
+Base *Base::addr;
+/*{{{  Base::Base ()*/
+Base::Base ()
+{
+  printf ("Base (%u) ctor %x\n", sizeof (Base), this);
+  if (fail) ;
+  else if (addr)
+    fail = 1;
+  else
+    addr = this;
+}
+/*}}}*/
+/*{{{  Base::~Base ()*/
+Base::~Base ()
+{
+  printf ("Base dtor %x\n", this);
+  if (fail)
+    ;
+  else if (this != addr)
+    fail = 2;
+  else
+    addr = 0;
+}
+/*}}}*/
+
+/*{{{  struct M10 : virtual Base*/
+struct M10 : virtual Base
+{
+  int m;
+  static M10 *addr;
+  
+  M10 ();
+  virtual ~M10 ();
+};
+/*}}}*/
+M10 *M10::addr;
+/*{{{  M10::M10 ()*/
+M10::M10 ()
+{
+  printf ("M10 (%u) ctor %x\n", sizeof (M10), this);
+  if (fail) ;
+  else if (addr)
+    fail = 3;
+  else
+    addr = this;
+}
+/*}}}*/
+/*{{{  M10::~M10 ()*/
+M10::~M10 ()
+{
+  printf ("M10 dtor %x\n", this);
+  if (fail)
+    ;
+  else if (this != addr)
+    fail = 4;
+  else
+    addr = 0;
+}
+/*}}}*/
+
+/*{{{  struct M4 : virtual Base, virtual M10*/
+struct M4 : virtual Base, virtual M10
+{
+  int m;
+  static M4 *addr;
+  
+  M4 ();
+  virtual ~M4 ();
+};
+/*}}}*/
+M4 *M4::addr;
+/*{{{  M4::M4 ()*/
+M4::M4 ()
+{
+  printf ("M4 (%u) ctor %x\n", sizeof (M4), this);
+  if (fail) ;
+  else if (addr)
+    fail = 5;
+  else
+    addr = this;
+}
+/*}}}*/
+/*{{{  M4::~M4 ()*/
+M4::~M4 ()
+{
+  printf ("M4 dtor %x\n", this);
+  if (fail)
+    ;
+  else if (this != addr)
+    fail = 6;
+  else
+    addr = 0;
+}
+/*}}}*/
+
+/*{{{  struct M5 : M4*/
+struct M5 : M4
+{
+  int m;
+  static M5 *addr;
+  
+  M5 ();
+  virtual ~M5 ();
+};
+/*}}}*/
+M5 *M5::addr;
+/*{{{  M5::M5 ()*/
+M5::M5 ()
+{
+  printf ("M5 (%u) ctor %x\n", sizeof (M5), this);
+  if (fail) ;
+  else if (addr)
+    fail = 7;
+  else
+    addr = this;
+}
+/*}}}*/
+/*{{{  M5::~M5 ()*/
+M5::~M5 ()
+{
+  printf ("M5 dtor %x\n", this);
+  if (fail)
+    ;
+  else if (this != addr)
+    fail = 8;
+  else
+    addr = 0;
+}
+/*}}}*/
+
+/*{{{  struct M9 : M5, virtual M10*/
+struct M9 : M5, virtual M10
+{
+  int m;
+  static M9 *addr;
+  
+  M9 ();
+  virtual ~M9 ();
+};
+/*}}}*/
+M9 *M9::addr;
+/*{{{  M9::M9 ()*/
+M9::M9 ()
+{
+  printf ("M9 (%u), ctor %x\n", sizeof (M9), this);
+  if (fail) ;
+  else if (addr)
+    fail = 9;
+  else
+    addr = this;
+}
+/*}}}*/
+/*{{{  M9::~M9 ()*/
+M9::~M9 ()
+{
+  printf ("M9 dtor %x\n", this);
+  if (fail)
+    ;
+  else if (this != addr)
+    fail = 10;
+  else
+    addr = 0;
+}
+/*}}}*/
+
+int main ()
+{
+  M9 *m9;
+  Base *r;
+  
+  m9 = new M9 ();
+  r = m9;
+  if (fail)
+    return fail;
+  void *top = dynamic_cast <void *> (r);
+  if (top != m9)
+    return 20;
+  r->~Base ();
+  
+  return fail;
+}
This page took 0.105837 seconds and 5 git commands to generate.