OSDN Git Service

* cp-tree.h (commonparms): Remove prototype.
[pf3gnuchains/gcc-fork.git] / gcc / cp / search.c
index 47d08f3..8d5ae65 100644 (file)
@@ -1,7 +1,7 @@
 /* Breadth-first and depth-first routines for
    searching multiple-inheritance lattice for GNU C++.
    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -34,31 +34,30 @@ Boston, MA 02111-1307, USA.  */
 #include "rtl.h"
 #include "output.h"
 #include "toplev.h"
-#include "stack.h"
-
-struct vbase_info 
-{
-  /* The class dominating the hierarchy.  */
-  tree type;
-  /* A pointer to a complete object of the indicated TYPE.  */
-  tree decl_ptr;
-  tree inits;
-};
 
 static int is_subobject_of_p (tree, tree);
-static base_kind lookup_base_r (tree, tree, base_access, bool, tree *);
-static int dynamic_cast_base_recurse (tree, tree, bool, tree *);
-static tree dfs_debug_unmarkedp (tree, int, void *);
+static tree dfs_lookup_base (tree, void *);
+static tree dfs_dcast_hint_pre (tree, void *);
+static tree dfs_dcast_hint_post (tree, void *);
 static tree dfs_debug_mark (tree, void *);
+static tree dfs_walk_once_r (tree, tree (*pre_fn) (tree, void *),
+                            tree (*post_fn) (tree, void *), void *data);
+static void dfs_unmark_r (tree);
 static int check_hidden_convs (tree, int, int, tree, tree, tree);
 static tree split_conversions (tree, tree, tree, tree);
 static int lookup_conversions_r (tree, int, int,
                                 tree, tree, tree, tree, tree *, tree *);
 static int look_for_overrides_r (tree, tree);
-static tree lookup_field_queue_p (tree, int, void *);
 static tree lookup_field_r (tree, void *);
-static tree dfs_accessible_queue_p (tree, int, void *);
-static tree dfs_accessible_p (tree, void *);
+static tree dfs_accessible_post (tree, void *);
+static tree dfs_walk_once_accessible_r (tree, bool, bool,
+                                       tree (*pre_fn) (tree, void *),
+                                       tree (*post_fn) (tree, void *),
+                                       void *data);
+static tree dfs_walk_once_accessible (tree, bool,
+                                     tree (*pre_fn) (tree, void *),
+                                     tree (*post_fn) (tree, void *),
+                                     void *data);
 static tree dfs_access_in_type (tree, void *);
 static access_kind access_in_type (tree, tree);
 static int protected_accessible_p (tree, tree, tree);
@@ -78,95 +77,84 @@ static int n_contexts_saved;
 #endif /* GATHER_STATISTICS */
 
 \f
-/* Worker for lookup_base.  BINFO is the binfo we are searching at,
-   BASE is the RECORD_TYPE we are searching for.  ACCESS is the
-   required access checks.  IS_VIRTUAL indicates if BINFO is morally
-   virtual.
-
-   If BINFO is of the required type, then *BINFO_PTR is examined to
-   compare with any other instance of BASE we might have already
-   discovered. *BINFO_PTR is initialized and a base_kind return value
-   indicates what kind of base was located.
-
-   Otherwise BINFO's bases are searched.  */
-
-static base_kind
-lookup_base_r (tree binfo, tree base, base_access access,
-              bool is_virtual,                 /* inside a virtual part */
-              tree *binfo_ptr)
+/* Data for lookup_base and its workers.  */
+
+struct lookup_base_data_s
 {
-  int i;
-  tree base_binfo;
-  base_kind found = bk_not_base;
-  
-  if (same_type_p (BINFO_TYPE (binfo), base))
-    {
-      /* We have found a base. Check against what we have found
-         already.  */
-      found = bk_same_type;
-      if (is_virtual)
-       found = bk_via_virtual;
-      
-      if (!*binfo_ptr)
-       *binfo_ptr = binfo;
-      else if (binfo != *binfo_ptr)
-       {
-         if (access != ba_any)
-           *binfo_ptr = NULL;
-         else if (!is_virtual)
-           /* Prefer a non-virtual base.  */
-           *binfo_ptr = binfo;
-         found = bk_ambig;
-       }
-      
-      return found;
-    }
-  
-  for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
-    {
-      base_kind bk;
+  tree t;              /* type being searched.  */
+  tree base;            /* The base type we're looking for.  */
+  tree binfo;           /* Found binfo.  */
+  bool via_virtual;    /* Found via a virtual path.  */
+  bool ambiguous;      /* Found multiply ambiguous */
+  bool repeated_base;   /* Whether there are repeated bases in the
+                           hierarchy.  */
+  bool want_any;       /* Whether we want any matching binfo.  */
+};
 
-      bk = lookup_base_r (base_binfo, base,
-                         access,
-                         is_virtual || BINFO_VIRTUAL_P (base_binfo),
-                         binfo_ptr);
+/* Worker function for lookup_base.  See if we've found the desired
+   base and update DATA_ (a pointer to LOOKUP_BASE_DATA_S).  */
 
-      switch (bk)
+static tree
+dfs_lookup_base (tree binfo, void *data_)
+{
+  struct lookup_base_data_s *data = data_;
+
+  if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
+    {
+      if (!data->binfo)
        {
-       case bk_ambig:
-         if (access != ba_any)
-           return bk;
-         found = bk;
-         break;
+         data->binfo = binfo;
+         data->via_virtual
+           = binfo_via_virtual (data->binfo, data->t) != NULL_TREE;
          
-       case bk_same_type:
-         bk = bk_proper_base;
-         /* Fall through.  */
-       case bk_proper_base:
-         gcc_assert (found == bk_not_base);
-         found = bk;
-         break;
+         if (!data->repeated_base)
+           /* If there are no repeated bases, we can stop now.  */
+           return binfo;
          
-       case bk_via_virtual:
-         if (found != bk_ambig)
-           found = bk;
-         break;
+         if (data->want_any && !data->via_virtual)
+           /* If this is a non-virtual base, then we can't do
+              better.  */
+           return binfo;
          
-       case bk_not_base:
-         break;
+         return dfs_skip_bases;
+       }
+      else
+       {
+         gcc_assert (binfo != data->binfo);
+         
+         /* We've found more than one matching binfo.  */
+         if (!data->want_any)
+           {
+             /* This is immediately ambiguous.  */
+             data->binfo = NULL_TREE;
+             data->ambiguous = true;
+             return error_mark_node;
+           }
 
-       default:
-         gcc_unreachable ();
+         /* Prefer one via a non-virtual path.  */
+         if (!binfo_via_virtual (binfo, data->t))
+           {
+             data->binfo = binfo;
+             data->via_virtual = false;
+             return binfo;
+           }
+
+         /* There must be repeated bases, otherwise we'd have stopped
+            on the first base we found.  */
+         return dfs_skip_bases;
        }
     }
-  return found;
+  
+  return NULL_TREE;
 }
 
 /* Returns true if type BASE is accessible in T.  (BASE is known to be
-   a (possibly non-proper) base class of T.)  */
+   a (possibly non-proper) base class of T.)  If CONSIDER_LOCAL_P is
+   true, consider any special access of the current scope, or access
+   bestowed by friendship.  */
 
 bool
-accessible_base_p (tree t, tree base)
+accessible_base_p (tree t, tree base, bool consider_local_p)
 {
   tree decl;
 
@@ -186,7 +174,7 @@ accessible_base_p (tree t, tree base)
     decl = TREE_CHAIN (decl);
   while (ANON_AGGR_TYPE_P (t))
     t = TYPE_CONTEXT (t);
-  return accessible_p (t, decl);
+  return accessible_p (t, decl, consider_local_p);
 }
 
 /* Lookup BASE in the hierarchy dominated by T.  Do access checking as
@@ -202,8 +190,8 @@ accessible_base_p (tree t, tree base)
 tree
 lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
 {
-  tree binfo = NULL_TREE;      /* The binfo we've found so far.  */
-  tree t_binfo = NULL_TREE;
+  tree binfo;
+  tree t_binfo;
   base_kind bk;
   
   if (t == error_mark_node || base == error_mark_node)
@@ -219,7 +207,7 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
       t_binfo = t;
       t = BINFO_TYPE (t);
     }
-  else  
+  else
     {
       t = complete_type (TYPE_MAIN_VARIANT (t));
       t_binfo = TYPE_BINFO (t);
@@ -228,9 +216,33 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
   base = complete_type (TYPE_MAIN_VARIANT (base));
 
   if (t_binfo)
-    bk = lookup_base_r (t_binfo, base, access, 0, &binfo);
+    {
+      struct lookup_base_data_s data;
+
+      data.t = t;
+      data.base = base;
+      data.binfo = NULL_TREE;
+      data.ambiguous = data.via_virtual = false;
+      data.repeated_base = CLASSTYPE_REPEATED_BASE_P (t);
+      data.want_any = access == ba_any;
+
+      dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
+      binfo = data.binfo;
+      
+      if (!binfo)
+       bk = data.ambiguous ? bk_ambig : bk_not_base;
+      else if (binfo == t_binfo)
+       bk = bk_same_type;
+      else if (data.via_virtual)
+       bk = bk_via_virtual;
+      else
+       bk = bk_proper_base;
+    }
   else
-    bk = bk_not_base;
+    {
+      binfo = NULL_TREE;
+      bk = bk_not_base;
+    }
 
   /* Check that the base is unambiguous and accessible.  */
   if (access != ba_any)
@@ -240,16 +252,15 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
        break;
 
       case bk_ambig:
-       binfo = NULL_TREE;
        if (!(access & ba_quiet))
          {
-           error ("`%T' is an ambiguous base of `%T'", base, t);
+           error ("%qT is an ambiguous base of %qT", base, t);
            binfo = error_mark_node;
          }
        break;
 
       default:
-       if ((access & ~ba_quiet) != ba_ignore
+       if ((access & ba_check_bit)
            /* If BASE is incomplete, then BASE and TYPE are probably
               the same, in which case BASE is accessible.  If they
               are not the same, then TYPE is invalid.  In that case,
@@ -257,11 +268,11 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
               there's no implicit typedef to use in the code that
               follows, so we skip the check.  */
            && COMPLETE_TYPE_P (base)
-           && !accessible_base_p (t, base))
+           && !accessible_base_p (t, base, !(access & ba_ignore_scope)))
          {
            if (!(access & ba_quiet))
              {
-               error ("`%T' is an inaccessible base of `%T'", base, t);
+               error ("%qT is an inaccessible base of %qT", base, t);
                binfo = error_mark_node;
              }
            else
@@ -277,49 +288,58 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
   return binfo;
 }
 
-/* Worker function for get_dynamic_cast_base_type.  */
+/* Data for dcast_base_hint walker.  */
 
-static int
-dynamic_cast_base_recurse (tree subtype, tree binfo, bool is_via_virtual,
-                          tree *offset_ptr)
+struct dcast_data_s
 {
-  VEC (tree) *accesses;
-  tree base_binfo;
-  int i;
-  int worst = -2;
+  tree subtype;   /* The base type we're looking for.  */
+  int virt_depth; /* Number of virtual bases encountered from most
+                    derived.  */
+  tree offset;    /* Best hint offset discovered so far.  */
+  bool repeated_base;  /* Whether there are repeated bases in the
+                         hierarchy.  */
+};
+
+/* Worker for dcast_base_hint.  Search for the base type being cast
+   from.  */
+
+static tree
+dfs_dcast_hint_pre (tree binfo, void *data_)
+{
+  struct dcast_data_s *data = data_;
+
+  if (BINFO_VIRTUAL_P (binfo))
+    data->virt_depth++;
   
-  if (BINFO_TYPE (binfo) == subtype)
+  if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->subtype))
     {
-      if (is_via_virtual)
-        return -1;
+      if (data->virt_depth)
+       {
+         data->offset = ssize_int (-1);
+         return data->offset;
+       }
+      if (data->offset)
+       data->offset = ssize_int (-3);
       else
-        {
-          *offset_ptr = BINFO_OFFSET (binfo);
-          return 0;
-        }
+       data->offset = BINFO_OFFSET (binfo);
+
+      return data->repeated_base ? dfs_skip_bases : data->offset;
     }
-  
-  accesses = BINFO_BASE_ACCESSES (binfo);
-  for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
-    {
-      tree base_access = VEC_index (tree, accesses, i);
-      int rval;
-      
-      if (base_access != access_public_node)
-        continue;
-      rval = dynamic_cast_base_recurse
-             (subtype, base_binfo,
-              is_via_virtual || BINFO_VIRTUAL_P (base_binfo), offset_ptr);
-      if (worst == -2)
-        worst = rval;
-      else if (rval >= 0)
-        worst = worst >= 0 ? -3 : worst;
-      else if (rval == -1)
-        worst = -1;
-      else if (rval == -3 && worst != -1)
-        worst = -3;
-    }
-  return worst;
+
+  return NULL_TREE;
+}
+
+/* Worker for dcast_base_hint.  Track the virtual depth.  */
+
+static tree
+dfs_dcast_hint_post (tree binfo, void *data_)
+{
+  struct dcast_data_s *data = data_;
+
+  if (BINFO_VIRTUAL_P (binfo))
+    data->virt_depth--;
+
+  return NULL_TREE;
 }
 
 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
@@ -334,16 +354,18 @@ dynamic_cast_base_recurse (tree subtype, tree binfo, bool is_via_virtual,
    BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases.  */
 
 tree
-get_dynamic_cast_base_type (tree subtype, tree target)
+dcast_base_hint (tree subtype, tree target)
 {
-  tree offset = NULL_TREE;
-  int boff = dynamic_cast_base_recurse (subtype, TYPE_BINFO (target),
-                                        false, &offset);
+  struct dcast_data_s data;
+
+  data.subtype = subtype;
+  data.virt_depth = 0;
+  data.offset = NULL_TREE;
+  data.repeated_base = CLASSTYPE_REPEATED_BASE_P (target);
   
-  if (!boff)
-    return offset;
-  offset = ssize_int (boff);
-  return offset;
+  dfs_walk_once_accessible (TYPE_BINFO (target), /*friends=*/false,
+                           dfs_dcast_hint_pre, dfs_dcast_hint_post, &data);
+  return data.offset ? data.offset : ssize_int (-2);
 }
 
 /* Search for a member with name NAME in a multiple inheritance
@@ -448,13 +470,10 @@ lookup_field_1 (tree type, tree name, bool want_type)
             the compiler cannot handle that.  Once the class is
             defined, USING_DECLs are purged from TYPE_FIELDS; see
             handle_using_decl.  However, we make special efforts to
-            make using-declarations in template classes work
-            correctly.  */
-         if (CLASSTYPE_TEMPLATE_INFO (type)
-             && !CLASSTYPE_USE_TEMPLATE (type)
-             && !TREE_TYPE (field))
-           ;
-         else
+            make using-declarations in class templates and class
+            template partial specializations work correctly noticing
+            that dependent USING_DECL's do not have TREE_TYPE set.  */
+         if (TREE_TYPE (field))
            continue;
        }
 
@@ -474,7 +493,13 @@ lookup_field_1 (tree type, tree name, bool want_type)
   return NULL_TREE;
 }
 
-/* There are a number of cases we need to be aware of here:
+/* Return the FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, or
+   NAMESPACE_DECL corresponding to the innermost non-block scope.  */  
+
+tree
+current_scope (void)
+{
+  /* There are a number of cases we need to be aware of here:
                         current_class_type     current_function_decl
      global                    NULL                    NULL
      fn-local                  NULL                    SET
@@ -482,30 +507,26 @@ lookup_field_1 (tree type, tree name, bool want_type)
      class->fn                 SET                     SET
      fn->class                 SET                     SET
 
-   Those last two make life interesting.  If we're in a function which is
-   itself inside a class, we need decls to go into the fn's decls (our
-   second case below).  But if we're in a class and the class itself is
-   inside a function, we need decls to go into the decls for the class.  To
-   achieve this last goal, we must see if, when both current_class_ptr and
-   current_function_decl are set, the class was declared inside that
-   function.  If so, we know to put the decls into the class's scope.  */
-
-tree
-current_scope (void)
-{
-  if (current_function_decl == NULL_TREE)
-    return current_class_type;
-  if (current_class_type == NULL_TREE)
+     Those last two make life interesting.  If we're in a function which is
+     itself inside a class, we need decls to go into the fn's decls (our
+     second case below).  But if we're in a class and the class itself is
+     inside a function, we need decls to go into the decls for the class.  To
+     achieve this last goal, we must see if, when both current_class_ptr and
+     current_function_decl are set, the class was declared inside that
+     function.  If so, we know to put the decls into the class's scope.  */
+  if (current_function_decl && current_class_type
+      && ((DECL_FUNCTION_MEMBER_P (current_function_decl)
+          && same_type_p (DECL_CONTEXT (current_function_decl),
+                          current_class_type))
+         || (DECL_FRIEND_CONTEXT (current_function_decl)
+             && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
+                             current_class_type))))
     return current_function_decl;
-  if ((DECL_FUNCTION_MEMBER_P (current_function_decl)
-       && same_type_p (DECL_CONTEXT (current_function_decl),
-                      current_class_type))
-      || (DECL_FRIEND_CONTEXT (current_function_decl)
-         && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
-                         current_class_type)))
+  if (current_class_type)
+    return current_class_type;
+  if (current_function_decl)
     return current_function_decl;
-
-  return current_class_type;
+  return current_namespace;
 }
 
 /* Returns nonzero if we are currently in a function scope.  Note
@@ -533,9 +554,8 @@ at_class_scope_p (void)
 bool
 at_namespace_scope_p (void)
 {
-  /* We are in a namespace scope if we are not it a class scope or a
-     function scope.  */
-  return !current_scope();
+  tree cs = current_scope ();
+  return cs && TREE_CODE (cs) == NAMESPACE_DECL;
 }
 
 /* Return the scope of DECL, as appropriate when doing name-lookup.  */
@@ -663,10 +683,6 @@ dfs_access_in_type (tree binfo, void *data)
   /* Note the access to DECL in TYPE.  */
   SET_BINFO_ACCESS (binfo, access);
 
-  /* Mark TYPE as visited so that if we reach it again we do not
-     duplicate our efforts here.  */
-  BINFO_MARKED (binfo) = 1;
-
   return NULL_TREE;
 }
 
@@ -688,47 +704,11 @@ access_in_type (tree type, tree decl)
     The algorithm we use is to make a post-order depth-first traversal
     of the base-class hierarchy.  As we come up the tree, we annotate
     each node with the most lenient access.  */
-  dfs_walk_real (binfo, 0, dfs_access_in_type, unmarkedp, decl);
-  dfs_walk (binfo, dfs_unmark, markedp,  0);
+  dfs_walk_once (binfo, NULL, dfs_access_in_type, decl);
 
   return BINFO_ACCESS (binfo);
 }
 
-/* Called from accessible_p via dfs_walk.  */
-
-static tree
-dfs_accessible_queue_p (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  
-  if (BINFO_MARKED (binfo))
-    return NULL_TREE;
-
-  /* If this class is inherited via private or protected inheritance,
-     then we can't see it, unless we are a friend of the derived class.  */
-  if (BINFO_BASE_ACCESS (derived, ix) != access_public_node
-      && !is_friend (BINFO_TYPE (derived), current_scope ()))
-    return NULL_TREE;
-
-  return binfo;
-}
-
-/* Called from accessible_p via dfs_walk.  */
-
-static tree
-dfs_accessible_p (tree binfo, void *data ATTRIBUTE_UNUSED)
-{
-  access_kind access;
-
-  BINFO_MARKED (binfo) = 1;
-  access = BINFO_ACCESS (binfo);
-  if (access != ak_none
-      && is_friend (BINFO_TYPE (binfo), current_scope ()))
-    return binfo;
-
-  return NULL_TREE;
-}
-
 /* Returns nonzero if it is OK to access DECL through an object
    indicated by BINFO in the context of DERIVED.  */
 
@@ -825,7 +805,7 @@ friend_accessible_p (tree scope, tree decl, tree binfo)
     {
       /* Perhaps this SCOPE is a member of a class which is a 
         friend.  */ 
-      if (DECL_CLASS_SCOPE_P (decl)
+      if (DECL_CLASS_SCOPE_P (scope)
          && friend_accessible_p (DECL_CONTEXT (scope), decl, binfo))
        return 1;
 
@@ -841,31 +821,38 @@ friend_accessible_p (tree scope, tree decl, tree binfo)
          return ret;
        }
     }
-  else if (CLASSTYPE_TEMPLATE_INFO (scope))
-    {
-      int ret;
-      /* Increment processing_template_decl to make sure that
-        dependent_type_p works correctly.  */
-      ++processing_template_decl;
-      ret = friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope), decl, binfo);
-      --processing_template_decl;
-      return ret;
-    }
 
   return 0;
 }
 
+/* Called via dfs_walk_once_accessible from accessible_p */
+
+static tree
+dfs_accessible_post (tree binfo, void *data ATTRIBUTE_UNUSED)
+{
+  if (BINFO_ACCESS (binfo) != ak_none)
+    {
+      tree scope = current_scope ();
+      if (scope && TREE_CODE (scope) != NAMESPACE_DECL
+         && is_friend (BINFO_TYPE (binfo), scope))
+       return binfo;
+    }
+  
+  return NULL_TREE;
+}
+
 /* DECL is a declaration from a base class of TYPE, which was the
    class used to name DECL.  Return nonzero if, in the current
    context, DECL is accessible.  If TYPE is actually a BINFO node,
    then we can tell in what context the access is occurring by looking
-   at the most derived class along the path indicated by BINFO.  */
+   at the most derived class along the path indicated by BINFO.  If
+   CONSIDER_LOCAL is true, do consider special access the current
+   scope or friendship thereof we might have.  */
 
 int 
-accessible_p (tree type, tree decl)
+accessible_p (tree type, tree decl, bool consider_local_p)
 {
   tree binfo;
-  tree t;
   tree scope;
   access_kind access;
 
@@ -917,15 +904,19 @@ accessible_p (tree type, tree decl)
 
     We walk the base class hierarchy, checking these conditions.  */
 
-  /* Figure out where the reference is occurring.  Check to see if
-     DECL is private or protected in this scope, since that will
-     determine whether protected access is allowed.  */
-  if (current_class_type)
-    protected_ok = protected_accessible_p (decl, current_class_type, binfo);
-
-  /* Now, loop through the classes of which we are a friend.  */
-  if (!protected_ok)
-    protected_ok = friend_accessible_p (scope, decl, binfo);
+  if (consider_local_p)
+    {
+      /* Figure out where the reference is occurring.  Check to see if
+        DECL is private or protected in this scope, since that will
+        determine whether protected access is allowed.  */
+      if (current_class_type)
+       protected_ok = protected_accessible_p (decl,
+                                              current_class_type, binfo);
+
+      /* Now, loop through the classes of which we are a friend.  */
+      if (!protected_ok)
+       protected_ok = friend_accessible_p (scope, decl, binfo);
+    }
 
   /* Standardize the binfo that access_in_type will use.  We don't
      need to know what path was chosen from this point onwards.  */
@@ -937,18 +928,15 @@ accessible_p (tree type, tree decl)
   if (access == ak_public
       || (access == ak_protected && protected_ok))
     return 1;
-  else
-    {
-      /* Walk the hierarchy again, looking for a base class that allows
-        access.  */
-      t = dfs_walk (binfo, dfs_accessible_p, dfs_accessible_queue_p, 0);
-      /* Clear any mark bits.  Note that we have to walk the whole tree
-        here, since we have aborted the previous walk from some point
-        deep in the tree.  */
-      dfs_walk (binfo, dfs_unmark, 0,  0);
-
-      return t != NULL_TREE;
-    }
+  
+  if (!consider_local_p)
+    return 0;
+  
+  /* Walk the hierarchy again, looking for a base class that allows
+     access.  */
+  return dfs_walk_once_accessible (binfo, /*friends=*/true,
+                                  NULL, dfs_accessible_post, NULL)
+    != NULL_TREE;
 }
 
 struct lookup_field_info {
@@ -969,33 +957,6 @@ struct lookup_field_info {
   const char *errstr;
 };
 
-/* Returns nonzero if BINFO is not hidden by the value found by the
-   lookup so far.  If BINFO is hidden, then there's no need to look in
-   it.  DATA is really a struct lookup_field_info.  Called from
-   lookup_field via breadth_first_search.  */
-
-static tree
-lookup_field_queue_p (tree derived, int ix, void *data)
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  struct lookup_field_info *lfi = (struct lookup_field_info *) data;
-
-  /* Don't look for constructors or destructors in base classes.  */
-  if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
-    return NULL_TREE;
-
-  /* If this base class is hidden by the best-known value so far, we
-     don't need to look.  */
-  if (lfi->rval_binfo && derived == lfi->rval_binfo)
-    return NULL_TREE;
-
-  /* If this is a dependent base, don't look in it.  */
-  if (BINFO_DEPENDENT_BASE_P (binfo))
-    return NULL_TREE;
-  
-  return binfo;
-}
-
 /* Within the scope of a template class, you can refer to the to the
    current specialization with the name of the template itself.  For
    example:
@@ -1075,6 +1036,16 @@ lookup_field_r (tree binfo, void *data)
   tree type = BINFO_TYPE (binfo);
   tree nval = NULL_TREE;
 
+  /* If this is a dependent base, don't look in it.  */
+  if (BINFO_DEPENDENT_BASE_P (binfo))
+    return NULL_TREE;
+  
+  /* If this base class is hidden by the best-known value so far, we
+     don't need to look.  */
+  if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
+      && !BINFO_VIRTUAL_P (binfo))
+    return dfs_skip_bases;
+
   /* First, look for a function.  There can't be a function and a data
      member with the same name, and if there's a function and a type
      with the same name, the type is hidden by the function.  */
@@ -1092,7 +1063,7 @@ lookup_field_r (tree binfo, void *data)
   /* If there is no declaration with the indicated name in this type,
      then there's nothing to do.  */
   if (!nval)
-    return NULL_TREE;
+    goto done;
 
   /* If we're looking up a type (as with an elaborated type specifier)
      we ignore all non-types we find.  */
@@ -1119,14 +1090,14 @@ lookup_field_r (tree binfo, void *data)
          if (e != NULL)
            nval = TYPE_MAIN_DECL (e->type);
          else 
-           return NULL_TREE;
+           goto done;
        }
     }
 
   /* You must name a template base class with a template-id.  */
   if (!same_type_p (type, lfi->type) 
       && template_self_reference_p (type, nval))
-    return NULL_TREE;
+    goto done;
 
   /* If the lookup already found a match, and the new value doesn't
      hide the old one, we might have an ambiguity.  */
@@ -1156,7 +1127,7 @@ lookup_field_r (tree binfo, void *data)
          /* Add the new value.  */
          lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
          TREE_TYPE (lfi->ambiguous) = error_mark_node;
-         lfi->errstr = "request for member `%D' is ambiguous";
+         lfi->errstr = "request for member %qD is ambiguous";
        }
     }
   else
@@ -1165,6 +1136,10 @@ lookup_field_r (tree binfo, void *data)
       lfi->rval_binfo = binfo;
     }
 
+ done:
+  /* Don't look for constructors or destructors in base classes.  */
+  if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
+    return dfs_skip_bases;
   return NULL_TREE;
 }
 
@@ -1251,8 +1226,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type)
   lfi.type = type;
   lfi.name = name;
   lfi.want_type = want_type;
-  dfs_walk_real (basetype_path, &lookup_field_r, 0,
-                &lookup_field_queue_p, &lfi);
+  dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
   rval = lfi.rval;
   rval_binfo = lfi.rval_binfo;
   if (rval_binfo)
@@ -1464,6 +1438,22 @@ lookup_fnfields_1 (tree type, tree name)
   return -1;
 }
 
+/* Like lookup_fnfields_1, except that the name is extracted from
+   FUNCTION, which is a FUNCTION_DECL or a TEMPLATE_DECL.  */
+
+int
+class_method_index_for_fn (tree class_type, tree function)
+{
+  gcc_assert (TREE_CODE (function) == FUNCTION_DECL
+             || DECL_FUNCTION_TEMPLATE_P (function));
+
+  return lookup_fnfields_1 (class_type,
+                           DECL_CONSTRUCTOR_P (function) ? ctor_identifier :
+                           DECL_DESTRUCTOR_P (function) ? dtor_identifier :
+                           DECL_NAME (function));
+}
+
+
 /* DECL is the result of a qualified name lookup.  QUALIFYING_SCOPE is
    the class or namespace used to qualify the name.  CONTEXT_CLASS is
    the class corresponding to the object in which DECL will be used.
@@ -1494,13 +1484,13 @@ adjust_result_of_qualified_name_lookup (tree decl,
         or ambiguity -- in either case, the choice of a static member
         function might make the usage valid.  */
       base = lookup_base (context_class, qualifying_scope,
-                         ba_ignore | ba_quiet, NULL);
+                         ba_unique | ba_quiet, NULL);
       if (base)
        {
          BASELINK_ACCESS_BINFO (decl) = base;
          BASELINK_BINFO (decl) 
            = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
-                          ba_ignore | ba_quiet,
+                          ba_unique | ba_quiet,
                           NULL);
        }
     }
@@ -1510,72 +1500,278 @@ adjust_result_of_qualified_name_lookup (tree decl,
 
 \f
 /* Walk the class hierarchy within BINFO, in a depth-first traversal.
-   PREFN is called in preorder, while POSTFN is called in postorder.
-   If they ever returns a non-NULL value, that value is immediately
-   returned and the walk is terminated.  Both PREFN and POSTFN can be
-   NULL.  At each node, PREFN and POSTFN are passed the binfo to
-   examine.  Before each base-binfo of BINFO is walked, QFN is called.
-   If the value returned is nonzero, the base-binfo is walked;
-   otherwise it is not.  If QFN is NULL, it is treated as a function
-   which always returns 1.  All callbacks are passed DATA whenever
-   they are called.  */
+   PRE_FN is called in preorder, while POST_FN is called in postorder.
+   If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
+   walked.  If PRE_FN or POST_FN returns a different non-NULL value,
+   that value is immediately returned and the walk is terminated.  One
+   of PRE_FN and POST_FN can be NULL.  At each node, PRE_FN and
+   POST_FN are passed the binfo to examine and the caller's DATA
+   value.  All paths are walked, thus virtual and morally virtual
+   binfos can be multiply walked.  */
 
 tree
-dfs_walk_real (tree binfo,
-              tree (*prefn) (tree, void *),
-              tree (*postfn) (tree, void *),
-              tree (*qfn) (tree, int, void *),
-              void *data)
+dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
+             tree (*post_fn) (tree, void *), void *data)
 {
-  int i;
+  tree rval;
+  unsigned ix;
   tree base_binfo;
-  tree rval = NULL_TREE;
+  
+  /* Call the pre-order walking function.  */
+  if (pre_fn)
+    {
+      rval = pre_fn (binfo, data);
+      if (rval)
+       {
+         if (rval == dfs_skip_bases)
+           goto skip_bases;
+         return rval;
+       }
+    }
+
+  /* Find the next child binfo to walk.  */
+  for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+    {
+      rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
+      if (rval)
+       return rval;
+    }
+
+ skip_bases:
+  /* Call the post-order walking function.  */
+  if (post_fn)
+    {
+      rval = post_fn (binfo, data);
+      gcc_assert (rval != dfs_skip_bases);
+      return rval;
+    }
+  
+  return NULL_TREE;
+}
+
+/* Worker for dfs_walk_once.  This behaves as dfs_walk_all, except
+   that binfos are walked at most once.  */
 
+static tree
+dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
+                tree (*post_fn) (tree, void *), void *data)
+{
+  tree rval;
+  unsigned ix;
+  tree base_binfo;
+  
   /* Call the pre-order walking function.  */
-  if (prefn)
+  if (pre_fn)
+    {
+      rval = pre_fn (binfo, data);
+      if (rval)
+       {
+         if (rval == dfs_skip_bases)
+           goto skip_bases;
+         
+         return rval;
+       }
+    }
+
+  /* Find the next child binfo to walk.  */
+  for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
     {
-      rval = (*prefn) (binfo, data);
+      if (BINFO_VIRTUAL_P (base_binfo))
+       {
+         if (BINFO_MARKED (base_binfo))
+           continue;
+         BINFO_MARKED (base_binfo) = 1;
+       }
+  
+      rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, data);
       if (rval)
        return rval;
     }
+  
+ skip_bases:
+  /* Call the post-order walking function.  */
+  if (post_fn)
+    {
+      rval = post_fn (binfo, data);
+      gcc_assert (rval != dfs_skip_bases);
+      return rval;
+    }
+  
+  return NULL_TREE;
+}
 
+/* Worker for dfs_walk_once. Recursively unmark the virtual base binfos of
+   BINFO.  */
+   
+static void
+dfs_unmark_r (tree binfo)
+{
+  unsigned ix;
+  tree base_binfo;
+  
   /* Process the basetypes.  */
-  for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
+  for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+    {
+      if (BINFO_VIRTUAL_P (base_binfo))
+       {
+         if (!BINFO_MARKED (base_binfo))
+           continue;
+         BINFO_MARKED (base_binfo) = 0;
+       }
+      /* Only walk, if it can contain more virtual bases.  */
+      if (CLASSTYPE_VBASECLASSES (BINFO_TYPE (base_binfo)))
+       dfs_unmark_r (base_binfo);
+    }
+}
+
+/* Like dfs_walk_all, except that binfos are not multiply walked.  For
+   non-diamond shaped hierarchies this is the same as dfs_walk_all.
+   For diamond shaped hierarchies we must mark the virtual bases, to
+   avoid multiple walks.  */
+
+tree
+dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
+              tree (*post_fn) (tree, void *), void *data)
+{
+  tree rval;
+
+  gcc_assert (pre_fn || post_fn);
+  
+  if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
+    /* We are not diamond shaped, and therefore cannot encounter the
+       same binfo twice.  */
+    rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
+  else
     {
-      if (qfn)
+      rval = dfs_walk_once_r (binfo, pre_fn, post_fn, data);
+      if (!BINFO_INHERITANCE_CHAIN (binfo))
        {
-         base_binfo = (*qfn) (binfo, i, data);
-         if (!base_binfo)
+         /* We are at the top of the hierarchy, and can use the
+             CLASSTYPE_VBASECLASSES list for unmarking the virtual
+             bases.  */
+         VEC (tree) *vbases;
+         unsigned ix;
+         tree base_binfo;
+         
+         for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
+              VEC_iterate (tree, vbases, ix, base_binfo); ix++)
+           BINFO_MARKED (base_binfo) = 0;
+       }
+      else
+       dfs_unmark_r (binfo);
+    }
+  return rval;
+}
+
+/* Worker function for dfs_walk_once_accessible.  Behaves like
+   dfs_walk_once_r, except (a) FRIENDS_P is true if special
+   access given by the current context should be considered, (b) ONCE
+   indicates whether bases should be marked during traversal.  */
+
+static tree
+dfs_walk_once_accessible_r (tree binfo, bool friends_p, bool once,
+                           tree (*pre_fn) (tree, void *),
+                           tree (*post_fn) (tree, void *), void *data)
+{
+  tree rval = NULL_TREE;
+  unsigned ix;
+  tree base_binfo;
+
+  /* Call the pre-order walking function.  */
+  if (pre_fn)
+    {
+      rval = pre_fn (binfo, data);
+      if (rval)
+       {
+         if (rval == dfs_skip_bases)
+           goto skip_bases;
+         
+         return rval;
+       }
+    }
+
+  /* Find the next child binfo to walk.  */
+  for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+    {
+      bool mark = once && BINFO_VIRTUAL_P (base_binfo);
+
+      if (mark && BINFO_MARKED (base_binfo))
+       continue;
+  
+      /* If the base is inherited via private or protected
+        inheritance, then we can't see it, unless we are a friend of
+        the current binfo.  */
+      if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node)
+       {
+         tree scope;
+         if (!friends_p)
+           continue;
+         scope = current_scope ();
+         if (!scope 
+             || TREE_CODE (scope) == NAMESPACE_DECL
+             || !is_friend (BINFO_TYPE (binfo), scope))
            continue;
        }
-      rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
+
+      if (mark)
+       BINFO_MARKED (base_binfo) = 1;
+
+      rval = dfs_walk_once_accessible_r (base_binfo, friends_p, once,
+                                        pre_fn, post_fn, data);
       if (rval)
        return rval;
     }
-
+  
+ skip_bases:
   /* Call the post-order walking function.  */
-  if (postfn)
-    rval = (*postfn) (binfo, data);
+  if (post_fn)
+    {
+      rval = post_fn (binfo, data);
+      gcc_assert (rval != dfs_skip_bases);
+      return rval;
+    }
   
-  return rval;
+  return NULL_TREE;
 }
 
-/* Exactly like dfs_walk_real, except that there is no pre-order
-   function call and  FN is called in post-order.  */
+/* Like dfs_walk_once except that only accessible bases are walked.
+   FRIENDS_P indicates whether friendship of the local context
+   should be considered when determining accessibility.  */
 
-tree
-dfs_walk (tree binfo,
-         tree (*fn) (tree, void *),
-         tree (*qfn) (tree, int, void *),
-         void *data)
+static tree
+dfs_walk_once_accessible (tree binfo, bool friends_p,
+                           tree (*pre_fn) (tree, void *),
+                           tree (*post_fn) (tree, void *), void *data)
 {
-  return dfs_walk_real (binfo, 0, fn, qfn, data);
+  bool diamond_shaped = CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo));
+  tree rval = dfs_walk_once_accessible_r (binfo, friends_p, diamond_shaped,
+                                         pre_fn, post_fn, data);
+  
+  if (diamond_shaped)
+    {
+      if (!BINFO_INHERITANCE_CHAIN (binfo))
+       {
+         /* We are at the top of the hierarchy, and can use the
+             CLASSTYPE_VBASECLASSES list for unmarking the virtual
+             bases.  */
+         VEC (tree) *vbases;
+         unsigned ix;
+         tree base_binfo;
+         
+         for (vbases = CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)), ix = 0;
+              VEC_iterate (tree, vbases, ix, base_binfo); ix++)
+           BINFO_MARKED (base_binfo) = 0;
+       }
+      else
+       dfs_unmark_r (binfo);
+    }
+  return rval;
 }
 
 /* Check that virtual overrider OVERRIDER is acceptable for base function
    BASEFN. Issue diagnostic, and return zero, if unacceptable.  */
 
-int
+static int
 check_final_overrider (tree overrider, tree basefn)
 {
   tree over_type = TREE_TYPE (overrider);
@@ -1630,6 +1826,12 @@ check_final_overrider (tree overrider, tree basefn)
          over_return = non_reference (TREE_TYPE (over_type));
          if (CLASS_TYPE_P (over_return))
            fail = 2;
+         else
+           {
+             cp_warning_at ("deprecated covariant return type for %q#D",
+                            overrider);
+             cp_warning_at ("  overriding %q#D", basefn);
+           }
        }
       else
        fail = 2;
@@ -1642,14 +1844,14 @@ check_final_overrider (tree overrider, tree basefn)
     {
       if (fail == 1)
        {
-         cp_error_at ("invalid covariant return type for `%#D'", overrider);
-         cp_error_at ("  overriding `%#D'", basefn);
+         cp_error_at ("invalid covariant return type for %q#D", overrider);
+         cp_error_at ("  overriding %q#D", basefn);
        }
       else
        {
-         cp_error_at ("conflicting return type specified for `%#D'",
+         cp_error_at ("conflicting return type specified for %q#D",
                       overrider);
-         cp_error_at ("  overriding `%#D'", basefn);
+         cp_error_at ("  overriding %q#D", basefn);
        }
       DECL_INVALID_OVERRIDER_P (overrider) = 1;
       return 0;
@@ -1658,8 +1860,8 @@ check_final_overrider (tree overrider, tree basefn)
   /* Check throw specifier is at least as strict.  */
   if (!comp_except_specs (base_throw, over_throw, 0))
     {
-      cp_error_at ("looser throw specifier for `%#F'", overrider);
-      cp_error_at ("  overriding `%#F'", basefn);
+      cp_error_at ("looser throw specifier for %q#F", overrider);
+      cp_error_at ("  overriding %q#F", basefn);
       DECL_INVALID_OVERRIDER_P (overrider) = 1;
       return 0;
     }
@@ -1752,8 +1954,8 @@ look_for_overrides_r (tree type, tree fndecl)
        {
          /* A static member function cannot match an inherited
             virtual member function.  */
-         cp_error_at ("`%#D' cannot be declared", fndecl);
-         cp_error_at ("  since `%#D' declared in base class", fn);
+         cp_error_at ("%q#D cannot be declared", fndecl);
+         cp_error_at ("  since %q#D declared in base class", fn);
        }
       else
        {
@@ -1789,8 +1991,6 @@ dfs_get_pure_virtuals (tree binfo, void *data)
          VEC_safe_push (tree, CLASSTYPE_PURE_VIRTUALS (type),
                         BV_FN (virtuals));
     }
-  
-  BINFO_MARKED (binfo) = 1;
 
   return NULL_TREE;
 }
@@ -1809,39 +2009,8 @@ get_pure_virtuals (tree type)
      (A primary base is not interesting because the derived class of
      which it is a primary base will contain vtable entries for the
      pure virtuals in the base class.  */
-  dfs_walk (TYPE_BINFO (type), dfs_get_pure_virtuals, unmarkedp, type);
-  dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, type);
-}
-\f
-/* DEPTH-FIRST SEARCH ROUTINES.  */
-
-tree 
-markedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED) 
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  
-  return BINFO_MARKED (binfo) ? binfo : NULL_TREE; 
+  dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
 }
-
-tree
-unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED) 
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  
-  return !BINFO_MARKED (binfo) ? binfo : NULL_TREE; 
-}
-
-/* The worker functions for `dfs_walk'.  These do not need to
-   test anything (vis a vis marking) if they are paired with
-   a predicate function (above).  */
-
-tree
-dfs_unmark (tree binfo, void *data ATTRIBUTE_UNUSED)
-{
-  BINFO_MARKED (binfo) = 0;
-  return NULL_TREE;
-}
-
 \f
 /* Debug info for C++ classes can get very large; try to avoid
    emitting it everywhere.
@@ -1889,23 +2058,14 @@ dfs_debug_mark (tree binfo, void *data ATTRIBUTE_UNUSED)
 {
   tree t = BINFO_TYPE (binfo);
 
+  if (CLASSTYPE_DEBUG_REQUESTED (t))
+    return dfs_skip_bases;
+
   CLASSTYPE_DEBUG_REQUESTED (t) = 1;
 
   return NULL_TREE;
 }
 
-/* Returns BINFO if we haven't already noted that we want debugging
-   info for this base class.  */
-
-static tree 
-dfs_debug_unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  
-  return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo)) 
-         ? binfo : NULL_TREE);
-}
-
 /* Write out the debugging information for TYPE, whose vtable is being
    emitted.  Also walk through our bases and note that we want to
    write out information for them.  This avoids the problem of not
@@ -1922,7 +2082,7 @@ note_debug_info_needed (tree type)
       rest_of_type_compilation (type, toplevel_bindings_p ());
     }
 
-  dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
+  dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
 }
 \f
 void
@@ -1986,7 +2146,7 @@ check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
          tree *prev, other;
          
          if (!(virtual_depth || TREE_STATIC (level)))
-           /* Neither is morally virtual, so cannot hide each other. */
+           /* Neither is morally virtual, so cannot hide each other.  */
            continue;
          
          if (!TREE_VALUE (level))
@@ -2007,7 +2167,7 @@ check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
              if (same_type_p (to_type, TREE_TYPE (other)))
                {
                  if (they_hide_us)
-                   /* We are hidden. */
+                   /* We are hidden.  */
                    return 0;
 
                  if (we_hide_them)
@@ -2290,7 +2450,11 @@ binfo_from_vbase (tree binfo)
 tree
 binfo_via_virtual (tree binfo, tree limit)
 {
-  for (; binfo && (!limit || !same_type_p (BINFO_TYPE (binfo), limit));
+  if (limit && !CLASSTYPE_VBASECLASSES (limit))
+    /* LIMIT has no virtual bases, so BINFO cannot be via one.  */
+    return NULL_TREE;
+  
+  for (; binfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), limit);
        binfo = BINFO_INHERITANCE_CHAIN (binfo))
     {
       if (BINFO_VIRTUAL_P (binfo))
@@ -2326,7 +2490,7 @@ copied_binfo (tree binfo, tree here)
       
       cbinfo = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
       for (ix = 0; BINFO_BASE_ITERATE (cbinfo, ix, base_binfo); ix++)
-       if (BINFO_TYPE (base_binfo) == BINFO_TYPE (binfo))
+       if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
          {
            result = base_binfo;
            break;
@@ -2334,7 +2498,7 @@ copied_binfo (tree binfo, tree here)
     }
   else
     {
-      gcc_assert (BINFO_TYPE (here) == BINFO_TYPE (binfo));
+      gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here), BINFO_TYPE (binfo)));
       result = here;
     }
 
@@ -2351,7 +2515,7 @@ binfo_for_vbase (tree base, tree t)
   
   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
        VEC_iterate (tree, vbases, ix, binfo); ix++)
-    if (BINFO_TYPE (binfo) == base)
+    if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), base))
       return binfo;
   return NULL;
 }
@@ -2366,7 +2530,7 @@ original_binfo (tree binfo, tree here)
 {
   tree result = NULL;
   
-  if (BINFO_TYPE (binfo) == BINFO_TYPE (here))
+  if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (here)))
     result = here;
   else if (BINFO_VIRTUAL_P (binfo))
     result = (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here))
@@ -2383,7 +2547,8 @@ original_binfo (tree binfo, tree here)
          tree base_binfo;
          
          for (ix = 0; (base_binfo = BINFO_BASE_BINFO (base_binfos, ix)); ix++)
-           if (BINFO_TYPE (base_binfo) == BINFO_TYPE (binfo))
+           if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
+                                  BINFO_TYPE (binfo)))
              {
                result = base_binfo;
                break;