OSDN Git Service

PR c++/29138
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / tinfo.cc
index c381ff1..a16488b 100644 (file)
@@ -1,22 +1,23 @@
 // Methods for type_info for -*- C++ -*- Run Time Type Identification.
-// Copyright (C) 1994, 1996, 1998, 1999, 2000 Free Software Foundation
-
-// This file is part of GNU CC.
-
-// GNU CC is free software; you can redistribute it and/or modify
+// Copyright (C) 1994, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+// Free Software Foundation
+//
+// This file is part of GCC.
+//
+// GCC is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // the Free Software Foundation; either version 2, or (at your option)
 // any later version.
 
-// GNU CC is distributed in the hope that it will be useful,
+// GCC is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 
 // You should have received a copy of the GNU General Public License
-// along with GNU CC; see the file COPYING.  If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330,
-// Boston, MA 02111-1307, USA. 
+// along with GCC; see the file COPYING.  If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA. 
 
 // As a special exception, you may use this file as part of a free software
 // library without restriction.  Specifically, if other files instantiate
@@ -27,9 +28,8 @@
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#pragma implementation "typeinfo"
-
-#include <stddef.h>
+#include <bits/c++config.h>
+#include <cstddef>
 #include "tinfo.h"
 #include "new"                 // for placement new
 
@@ -41,28 +41,10 @@ std::type_info::
 ~type_info ()
 { }
 
-#if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
-// original (old) abi
-
-namespace
-{
-// ADDR is a pointer to an object.  Convert it to a pointer to a base,
-// using OFFSET.
-inline void*
-convert_to_base (void *addr, bool is_virtual, myint32 offset)
-{
-  if (!addr)
-    return NULL;
-
-  if (!is_virtual)
-    return (char *) addr + offset;
+std::bad_cast::~bad_cast() throw() { }
+std::bad_typeid::~bad_typeid() throw() { }
 
-  // Under the old ABI, the offset gives us the address of a pointer
-  // to the virtual base.
-  return *((void **) ((char *) addr + offset));
-}
-
-}
+#if !__GXX_MERGED_TYPEINFO_NAMES
 
 // We can't rely on common symbols being shared between shared objects.
 bool std::type_info::
@@ -71,476 +53,7 @@ operator== (const std::type_info& arg) const
   return (&arg == this) || (__builtin_strcmp (name (), arg.name ()) == 0);
 }
 
-extern "C" void
-__rtti_class (void *addr, const char *name,
-             const __class_type_info::base_info *bl, size_t bn)
-{ new (addr) __class_type_info (name, bl, bn); }
-
-extern "C" void
-__rtti_si (void *addr, const char *n, const std::type_info *ti)
-{
-  new (addr) __si_type_info
-    (n, static_cast <const __user_type_info &> (*ti));
-}
-
-extern "C" void
-__rtti_user (void *addr, const char *name)
-{ new (addr) __user_type_info (name); }
-
-// Upcast for catch checking. OBJPTR points to the thrown object and might be
-// NULL. Return 0 on failure, non-zero on success. Set *ADJPTR to adjusted
-// object pointer.
-int __user_type_info::
-upcast (const type_info &target, void *objptr,
-        void **adjptr) const
-{
-  upcast_result result;
-  
-  if (do_upcast (contained_public, target, objptr, result))
-    return 0;
-  *adjptr = result.target_obj;
-  return contained_public_p (result.whole2target);
-}
-
-// Down or cross cast for dynamic_cast. OBJPTR points to the most derrived
-// object, SUBPTR points to the static base object. Both must not be NULL.
-// TARGET specifies the desired target type, SUBTYPE specifies the static
-// type. Both must be defined. Returns adjusted object pointer on success,
-// NULL on failure. [expr.dynamic.cast]/8 says 'unambiguous public base'. This
-// itself is an ambiguous statement. We choose it to mean the base must be
-// separately unambiguous and public, rather than unambiguous considering only
-// public bases.
-void *__user_type_info::
-dyncast (int boff,
-         const type_info &target, void *objptr,
-         const type_info &subtype, void *subptr) const
-{
-  dyncast_result result;
-  
-  do_dyncast (boff, contained_public,
-              target, objptr, subtype, subptr, result);
-  if (!result.target_obj)
-    return NULL;
-  if (contained_public_p (result.target2sub))
-    return result.target_obj;
-  if (contained_public_p (sub_kind (result.whole2sub & result.whole2target)))
-    // Found a valid cross cast
-    return result.target_obj;
-  if (contained_nonvirtual_p (result.whole2sub))
-    // Found an invalid cross cast, which cannot also be a down cast
-    return NULL;
-  if (result.target2sub == unknown)
-    result.target2sub = static_cast <const __user_type_info &> (target)
-                        .find_public_subobj (boff, subtype,
-                                             result.target_obj, subptr);
-  if (contained_public_p (result.target2sub))
-    // Found a valid down cast
-    return result.target_obj;
-  // Must be an invalid down cast, or the cross cast wasn't bettered
-  return NULL;
-}
-
-// Catch cast helper. ACCESS_PATH is the access from the complete thrown
-// object to this base. TARGET is the desired type we want to catch. OBJPTR
-// points to this base within the throw object, it might be NULL. Fill in
-// RESULT with what we find. Return true, should we determine catch must fail.
-bool __user_type_info::
-do_upcast (sub_kind access_path,
-           const type_info &target, void *objptr,
-           upcast_result &__restrict result) const
-{
-  if (*this == target)
-    {
-      result.target_obj = objptr;
-      result.base_type = nonvirtual_base_type;
-      result.whole2target = access_path;
-      return contained_nonpublic_p (access_path);
-    }
-  return false;
-}
-
-// dynamic cast helper. ACCESS_PATH gives the access from the most derived
-// object to this base. TARGET indicates the desired type we want. OBJPTR
-// points to this base within the object. SUBTYPE indicates the static type
-// started from and SUBPTR points to that base within the most derived object.
-// Fill in RESULT with what we find. Return true if we have located an
-// ambiguous match.
-bool __user_type_info::
-do_dyncast (int, sub_kind access_path,
-            const type_info &target, void *objptr,
-            const type_info &subtype, void *subptr,
-            dyncast_result &__restrict result) const
-{
-  if (objptr == subptr && *this == subtype)
-    {
-      // The subobject we started from. Indicate how we are accessible from
-      // the most derived object.
-      result.whole2sub = access_path;
-      return false;
-    }
-  if (*this == target)
-    {
-      result.target_obj = objptr;
-      result.whole2target = access_path;
-      result.target2sub = not_contained;
-      return false;
-    }
-  return false;
-}
-
-// find_public_subobj helper. Return contained_public if we are the desired
-// subtype. OBJPTR points to this base type, SUBPTR points to the desired base
-// object.
-__user_type_info::sub_kind __user_type_info::
-do_find_public_subobj (int, const type_info &, void *objptr, void *subptr) const
-{
-  if (subptr == objptr)
-    // Must be our type, as the pointers match.
-    return contained_public;
-  return not_contained;
-}
-
-// catch helper for single public inheritance types. See
-// __user_type_info::do_upcast for semantics.
-bool __si_type_info::
-do_upcast (sub_kind access_path,
-           const type_info &target, void *objptr,
-           upcast_result &__restrict result) const
-{
-  if (*this == target)
-    {
-      result.target_obj = objptr;
-      result.base_type = nonvirtual_base_type;
-      result.whole2target = access_path;
-      return contained_nonpublic_p (access_path);
-    }
-  return base.do_upcast (access_path, target, objptr, result);
-}
-
-// dynamic cast helper for single public inheritance types. See
-// __user_type_info::do_dyncast for semantics. BOFF indicates how SUBTYPE
-// types are inherited by TARGET types.
-bool __si_type_info::
-do_dyncast (int boff, sub_kind access_path,
-            const type_info &target, void *objptr,
-            const type_info &subtype, void *subptr,
-            dyncast_result &__restrict result) const
-{
-  if (objptr == subptr && *this == subtype)
-    {
-      // The subobject we started from. Indicate how we are accessible from
-      // the most derived object.
-      result.whole2sub = access_path;
-      return false;
-    }
-  if (*this == target)
-    {
-      result.target_obj = objptr;
-      result.whole2target = access_path;
-      if (boff >= 0)
-        result.target2sub = ((char *)subptr - (char *)objptr) == boff
-              ? contained_public : not_contained;
-      else if (boff == -2)
-        result.target2sub = not_contained;
-      return false;
-    }
-  return base.do_dyncast (boff, access_path,
-                          target, objptr, subtype, subptr, result);
-}
-
-// find_public_subobj helper. See __user_type_info::do_find_public_subobj or
-// semantics. BOFF indicates how SUBTYPE types are inherited by the original
-// target object.
-__user_type_info::sub_kind __si_type_info::
-do_find_public_subobj (int boff, const type_info &subtype, void *objptr, void *subptr) const
-{
-  if (subptr == objptr && subtype == *this)
-    return contained_public;
-  return base.do_find_public_subobj (boff, subtype, objptr, subptr);
-}
-
-// catch helper for multiple or non-public inheritance types. See
-// __user_type_info::do_upcast for semantics.
-bool __class_type_info::
-do_upcast (sub_kind access_path,
-           const type_info &target, void *objptr,
-           upcast_result &__restrict result) const
-{
-  if (*this == target)
-    {
-      result.target_obj = objptr;
-      result.base_type = nonvirtual_base_type;
-      result.whole2target = access_path;
-      return contained_nonpublic_p (access_path);
-    }
-  
-  for (size_t i = n_bases; i--;)
-    {
-      upcast_result result2;
-      void *p = objptr;
-      sub_kind sub_access = access_path;
-      p = convert_to_base (p, 
-                          base_list[i].is_virtual,
-                          base_list[i].offset);
-      if (base_list[i].is_virtual)
-       sub_access = sub_kind (sub_access | contained_virtual_mask);
-      if (base_list[i].access != PUBLIC)
-        sub_access = sub_kind (sub_access & ~contained_public_mask);
-      if (base_list[i].base->do_upcast (sub_access, target, p, result2)
-          && !contained_virtual_p (result2.whole2target))
-        return true; // must fail
-      if (result2.base_type)
-        {
-          if (result2.base_type == nonvirtual_base_type
-              && base_list[i].is_virtual)
-            result2.base_type = base_list[i].base;
-          if (!result.base_type)
-            result = result2;
-          else if (result.target_obj != result2.target_obj)
-            {
-              // Found an ambiguity.
-             result.target_obj = NULL;
-             result.whole2target = contained_ambig;
-             return true;
-            }
-          else if (result.target_obj)
-            {
-              // Ok, found real object via a virtual path.
-              result.whole2target
-                  = sub_kind (result.whole2target | result2.whole2target);
-            }
-          else
-            {
-              // Dealing with a null pointer, need to check vbase
-              // containing each of the two choices.
-              if (result2.base_type == nonvirtual_base_type
-                  || result.base_type == nonvirtual_base_type
-                  || !(*result2.base_type == *result.base_type))
-                {
-                  // Already ambiguous, not virtual or via different virtuals.
-                  // Cannot match.
-                  result.whole2target = contained_ambig;
-                  return true;
-                }
-              result.whole2target
-                  = sub_kind (result.whole2target | result2.whole2target);
-            }
-        }
-    }
-  return false;
-}
-
-// dynamic cast helper for non-public or multiple inheritance types. See
-// __user_type_info::do_dyncast for overall semantics.
-// This is a big hairy function. Although the run-time behaviour of
-// dynamic_cast is simple to describe, it gives rise to some non-obvious
-// behaviour. We also desire to determine as early as possible any definite
-// answer we can get. Because it is unknown what the run-time ratio of
-// succeeding to failing dynamic casts is, we do not know in which direction
-// to bias any optimizations. To that end we make no particular effort towards
-// early fail answers or early success answers. Instead we try to minimize
-// work by filling in things lazily (when we know we need the information),
-// and opportunisticly take early success or failure results.
-bool __class_type_info::
-do_dyncast (int boff, sub_kind access_path,
-            const type_info &target, void *objptr,
-            const type_info &subtype, void *subptr,
-            dyncast_result &__restrict result) const
-{
-  if (objptr == subptr && *this == subtype)
-    {
-      // The subobject we started from. Indicate how we are accessible from
-      // the most derived object.
-      result.whole2sub = access_path;
-      return false;
-    }
-  if (*this == target)
-    {
-      result.target_obj = objptr;
-      result.whole2target = access_path;
-      if (boff >= 0)
-        result.target2sub = ((char *)subptr - (char *)objptr) == boff
-              ? contained_public : not_contained;
-      else if (boff == -2)
-        result.target2sub = not_contained;
-      return false;
-    }
-  bool result_ambig = false;
-  for (size_t i = n_bases; i--;)
-    {
-      dyncast_result result2;
-      void *p;
-      sub_kind sub_access = access_path;
-      p = convert_to_base (objptr, 
-                          base_list[i].is_virtual,
-                          base_list[i].offset);
-      if (base_list[i].is_virtual)
-       sub_access = sub_kind (sub_access | contained_virtual_mask);
-      if (base_list[i].access != PUBLIC)
-        sub_access = sub_kind (sub_access & ~contained_public_mask);
-      
-      bool result2_ambig
-          = base_list[i].base->do_dyncast (boff, sub_access,
-                                           target, p, subtype, subptr, result2);
-      result.whole2sub = sub_kind (result.whole2sub | result2.whole2sub);
-      if (result2.target2sub == contained_public
-          || result2.target2sub == contained_ambig)
-        {
-          result.target_obj = result2.target_obj;
-          result.whole2target = result2.whole2target;
-          result.target2sub = result2.target2sub;
-          // Found a downcast which can't be bettered or an ambiguous downcast
-          // which can't be disambiguated
-          return result2_ambig;
-        }
-      
-      if (!result_ambig && !result.target_obj)
-        {
-          // Not found anything yet.
-          result.target_obj = result2.target_obj;
-          result.whole2target = result2.whole2target;
-          result_ambig = result2_ambig;
-        }
-      else if (result.target_obj && result.target_obj == result2.target_obj)
-        {
-          // Found at same address, must be via virtual.  Pick the most
-          // accessible path.
-          result.whole2target =
-              sub_kind (result.whole2target | result2.whole2target);
-        }
-      else if ((result.target_obj && result2.target_obj)
-               || (result_ambig && result2.target_obj)
-               || (result2_ambig && result.target_obj))
-        {
-          // Found two different TARGET bases, or a valid one and a set of
-          // ambiguous ones, must disambiguate. See whether SUBOBJ is
-          // contained publicly within one of the non-ambiguous choices.
-          // If it is in only one, then that's the choice. If it is in
-          // both, then we're ambiguous and fail. If it is in neither,
-          // we're ambiguous, but don't yet fail as we might later find a
-          // third base which does contain SUBPTR.
-        
-          sub_kind new_sub_kind = result2.target2sub;
-          sub_kind old_sub_kind = result.target2sub;
-          
-          if (contained_nonvirtual_p (result.whole2sub))
-            {
-              // We already found SUBOBJ as a non-virtual base of most
-              // derived. Therefore if it is in either choice, it can only be
-              // in one of them, and we will already know.
-              if (old_sub_kind == unknown)
-                old_sub_kind = not_contained;
-              if (new_sub_kind == unknown)
-                new_sub_kind = not_contained;
-            }
-          else
-            {
-              const __user_type_info &t =
-                  static_cast <const __user_type_info &> (target);
-              
-              if (old_sub_kind >= not_contained)
-                ;// already calculated
-              else if (contained_nonvirtual_p (new_sub_kind))
-                // Already found non-virtually inside the other choice,
-                // cannot be in this.
-                old_sub_kind = not_contained;
-              else
-                old_sub_kind = t.find_public_subobj (boff, subtype,
-                                                     result.target_obj, subptr);
-          
-              if (new_sub_kind >= not_contained)
-                ;// already calculated
-              else if (contained_nonvirtual_p (old_sub_kind))
-                // Already found non-virtually inside the other choice,
-                // cannot be in this.
-                new_sub_kind = not_contained;
-              else
-                new_sub_kind = t.find_public_subobj (boff, subtype,
-                                                     result2.target_obj, subptr);
-            }
-          
-          // Neither sub_kind can be contained_ambig -- we bail out early
-          // when we find those.
-          if (contained_p (sub_kind (new_sub_kind ^ old_sub_kind)))
-            {
-              // Only on one choice, not ambiguous.
-              if (contained_p (new_sub_kind))
-                {
-                  // Only in new.
-                  result.target_obj = result2.target_obj;
-                  result.whole2target = result2.whole2target;
-                  result_ambig = false;
-                  old_sub_kind = new_sub_kind;
-                }
-              result.target2sub = old_sub_kind;
-              if (result.target2sub == contained_public)
-                return false; // Can't be an ambiguating downcast for later discovery.
-            }
-          else if (contained_p (sub_kind (new_sub_kind & old_sub_kind)))
-            {
-              // In both.
-              result.target_obj = NULL;
-              result.target2sub = contained_ambig;
-              return true;  // Fail.
-            }
-          else
-            {
-              // In neither publicly, ambiguous for the moment, but keep
-              // looking. It is possible that it was private in one or
-              // both and therefore we should fail, but that's just tough.
-              result.target_obj = NULL;
-              result.target2sub = not_contained;
-              result_ambig = true;
-            }
-        }
-      
-      if (result.whole2sub == contained_private)
-        // We found SUBOBJ as a private non-virtual base, therefore all
-        // cross casts will fail. We have already found a down cast, if
-        // there is one.
-        return result_ambig;
-    }
-
-  return result_ambig;
-}
-
-// find_public_subobj helper for non-public or multiple inheritance types. See
-// __user_type_info::do_find_public_subobj for semantics. We make use of BOFF
-// to prune the base class walk.
-__user_type_info::sub_kind __class_type_info::
-do_find_public_subobj (int boff, const type_info &subtype, void *objptr, void *subptr) const
-{
-  if (objptr == subptr && subtype == *this)
-    return contained_public;
-  
-  for (size_t i = n_bases; i--;)
-    {
-      if (base_list[i].access != PUBLIC)
-        continue; // Not public, can't be here.
-      void *p;
-
-      if (base_list[i].is_virtual && boff == -3)
-       // Not a virtual base, so can't be here.
-       continue;
-      
-      p = convert_to_base (objptr, 
-                          base_list[i].is_virtual,
-                          base_list[i].offset);
-
-      sub_kind base_kind = base_list[i].base->do_find_public_subobj
-                              (boff, subtype, p, subptr);
-      if (contained_p (base_kind))
-        {
-          if (base_list[i].is_virtual)
-            base_kind = sub_kind (base_kind | contained_virtual_mask);
-          return base_kind;
-        }
-    }
-  
-  return not_contained;
-}
-#else
-// new abi
+#endif
 
 namespace std {
 
@@ -572,19 +85,35 @@ __do_upcast (const abi::__class_type_info *, void **) const
   return false;
 }
 
-};
+}
 
 namespace {
 
 using namespace std;
 using namespace abi;
 
-// initial part of a vtable, this structure is used with offsetof, so we don't
+// Initial part of a vtable, this structure is used with offsetof, so we don't
 // have to keep alignments consistent manually.
-struct vtable_prefix {
-  ptrdiff_t whole_object;           // offset to most derived object
-  const __class_type_info *whole_type;  // pointer to most derived type_info
-  const void *origin;               // what a class's vptr points to
+struct vtable_prefix 
+{
+  // Offset to most derived object.
+  ptrdiff_t whole_object;
+
+  // Additional padding if necessary.
+#ifdef _GLIBCXX_VTABLE_PADDING
+  ptrdiff_t padding1;               
+#endif
+
+  // Pointer to most derived type_info.
+  const __class_type_info *whole_type;  
+
+  // Additional padding if necessary.
+#ifdef _GLIBCXX_VTABLE_PADDING
+  ptrdiff_t padding2;               
+#endif
+
+  // What a class's vptr points to.
+  const void *origin;               
 };
 
 template <typename T>
@@ -643,7 +172,7 @@ inline bool contained_nonvirtual_p (__class_type_info::__sub_kind access_path)
 static const __class_type_info *const nonvirtual_base_type =
     static_cast <const __class_type_info *> (0) + 1;
 
-}; // namespace
+} // namespace
 
 namespace __cxxabiv1
 {
@@ -661,38 +190,42 @@ __vmi_class_type_info::
 {}
 
 // __upcast_result is used to hold information during traversal of a class
-// heirarchy when catch matching.
+// hierarchy when catch matching.
 struct __class_type_info::__upcast_result
 {
   const void *dst_ptr;        // pointer to caught object
   __sub_kind part2dst;        // path from current base to target
-  int src_details;            // hints about the source type heirarchy
+  int src_details;            // hints about the source type hierarchy
   const __class_type_info *base_type; // where we found the target,
                               // if in vbase the __class_type_info of vbase
                               // if a non-virtual base then 1
                               // else NULL
-  public:
   __upcast_result (int d)
     :dst_ptr (NULL), part2dst (__unknown), src_details (d), base_type (NULL)
     {}
 };
 
 // __dyncast_result is used to hold information during traversal of a class
-// heirarchy when dynamic casting.
+// hierarchy when dynamic casting.
 struct __class_type_info::__dyncast_result
 {
   const void *dst_ptr;        // pointer to target object or NULL
   __sub_kind whole2dst;       // path from most derived object to target
   __sub_kind whole2src;       // path from most derived object to sub object
   __sub_kind dst2src;         // path from target to sub object
-  int whole_details;          // details of the whole class heirarchy
+  int whole_details;          // details of the whole class hierarchy
   
-  public:
   __dyncast_result (int details_ = __vmi_class_type_info::__flags_unknown_mask)
     :dst_ptr (NULL), whole2dst (__unknown),
      whole2src (__unknown), dst2src (__unknown),
      whole_details (details_)
     {}
+
+protected:
+  __dyncast_result(const __dyncast_result&);
+  
+  __dyncast_result&
+  operator=(const __dyncast_result&);
 };
 
 bool __class_type_info::
@@ -767,7 +300,7 @@ __do_find_public_src (ptrdiff_t src2dst,
   if (obj_ptr == src_ptr && *this == *src_type)
     return __contained_public;
   
-  for (size_t i = __base_count; i--;)
+  for (std::size_t i = __base_count; i--;)
     {
       if (!__base_info[i].__is_public_p ())
         continue; // Not public, can't be here.
@@ -783,7 +316,7 @@ __do_find_public_src (ptrdiff_t src2dst,
         }
       base = convert_to_base (base, is_virtual, offset);
       
-      __sub_kind base_kind = __base_info[i].__base->__do_find_public_src
+      __sub_kind base_kind = __base_info[i].__base_type->__do_find_public_src
                               (src2dst, base, src_type, src_ptr);
       if (contained_p (base_kind))
         {
@@ -894,7 +427,7 @@ __do_dyncast (ptrdiff_t src2dst,
     }
 
   bool result_ambig = false;
-  for (size_t i = __base_count; i--;)
+  for (std::size_t i = __base_count; i--;)
     {
       __dyncast_result result2 (result.whole_details);
       void const *base = obj_ptr;
@@ -920,7 +453,7 @@ __do_dyncast (ptrdiff_t src2dst,
         }
       
       bool result2_ambig
-          = __base_info[i].__base->__do_dyncast (src2dst, base_access,
+          = __base_info[i].__base_type->__do_dyncast (src2dst, base_access,
                                              dst_type, base,
                                              src_type, src_ptr, result2);
       result.whole2src = __sub_kind (result.whole2src | result2.whole2src);
@@ -953,8 +486,9 @@ __do_dyncast (ptrdiff_t src2dst,
           result.whole2dst =
               __sub_kind (result.whole2dst | result2.whole2dst);
         }
-      else if ((result.dst_ptr != 0 | result_ambig)
-               && (result2.dst_ptr != 0 | result2_ambig))
+      else if ((result.dst_ptr != 0 & result2.dst_ptr != 0)
+              || (result.dst_ptr != 0 & result2_ambig)
+              || (result2.dst_ptr != 0 & result_ambig))
         {
           // Found two different DST_TYPE bases, or a valid one and a set of
           // ambiguous ones, must disambiguate. See whether SRC_PTR is
@@ -972,7 +506,7 @@ __do_dyncast (ptrdiff_t src2dst,
                   || !(result.whole_details & __diamond_shaped_mask)))
             {
               // We already found SRC_PTR as a base of most derived, and
-              // either it was non-virtual, or the whole heirarchy is
+              // either it was non-virtual, or the whole hierarchy is
               // not-diamond shaped. Therefore if it is in either choice, it
               // can only be in one of them, and we will already know.
               if (old_sub_kind == __unknown)
@@ -1089,7 +623,7 @@ __do_upcast (const __class_type_info *dst, const void *obj_ptr,
   if (src_details & __flags_unknown_mask)
     src_details = __flags;
   
-  for (size_t i = __base_count; i--;)
+  for (std::size_t i = __base_count; i--;)
     {
       __upcast_result result2 (src_details);
       const void *base = obj_ptr;
@@ -1104,10 +638,10 @@ __do_upcast (const __class_type_info *dst, const void *obj_ptr,
       if (base)
         base = convert_to_base (base, is_virtual, offset);
       
-      if (__base_info[i].__base->__do_upcast (dst, base, result2))
+      if (__base_info[i].__base_type->__do_upcast (dst, base, result2))
         {
           if (result2.base_type == nonvirtual_base_type && is_virtual)
-            result2.base_type = __base_info[i].__base;
+            result2.base_type = __base_info[i].__base_type;
           if (contained_p (result2.part2dst) && !is_public)
             result2.part2dst = __sub_kind (result2.part2dst & ~__contained_public_mask);
           
@@ -1206,5 +740,4 @@ __dynamic_cast (const void *src_ptr,    // object started from
   return NULL;
 }
 
-}; // namespace __cxxabiv1
-#endif
+} // namespace __cxxabiv1