OSDN Git Service

PR c++/26114, c++/26115
[pf3gnuchains/gcc-fork.git] / gcc / cp / class.c
index 1007ebb..0edade8 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to building classes and their related objects.
    Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004  Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -17,8 +17,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 /* High-level class interface.  */
@@ -35,6 +35,8 @@ Boston, MA 02111-1307, USA.  */
 #include "toplev.h"
 #include "target.h"
 #include "convert.h"
+#include "cgraph.h"
+#include "tree-dump.h"
 
 /* The number of nested classes being processed.  If we are not in the
    scope of any class, this is zero.  */
@@ -58,6 +60,10 @@ typedef struct class_stack_node {
 
   /* If were defining TYPE, the names used in this class.  */
   splay_tree names_used;
+
+  /* Nonzero if this class is no longer open, because of a call to
+     push_to_top_level.  */
+  size_t hidden;
 }* class_stack_node_t;
 
 typedef struct vtbl_init_data_s
@@ -79,7 +85,7 @@ typedef struct vtbl_init_data_s
   tree vbase;
   /* The functions in vbase for which we have already provided vcall
      offsets.  */
-  varray_type fns;
+  VEC(tree,gc) *fns;
   /* The vtable index of the next vcall or vbase offset.  */
   tree index;
   /* Nonzero if we are building the initializer for the primary
@@ -101,9 +107,12 @@ typedef int (*subobject_offset_fn) (tree, tree, splay_tree);
 static int current_class_stack_size;
 static class_stack_node_t current_class_stack;
 
+/* The size of the largest empty class seen in this translation unit.  */
+static GTY (()) tree sizeof_biggest_empty_class;
+
 /* An array of all local classes present in this translation unit, in
    declaration order.  */
-varray_type local_classes;
+VEC(tree,gc) *local_classes;
 
 static tree get_vfield_name (tree);
 static void finish_struct_anon (tree);
@@ -116,7 +125,6 @@ static void modify_vtable_entry (tree, tree, tree, tree, tree *);
 static void finish_struct_bits (tree);
 static int alter_access (tree, tree, tree);
 static void handle_using_decl (tree, tree);
-static void check_for_override (tree, tree);
 static tree dfs_modify_vtables (tree, void *);
 static tree modify_all_vtables (tree, tree);
 static void determine_primary_bases (tree);
@@ -124,7 +132,7 @@ static void finish_struct_methods (tree);
 static void maybe_warn_about_overly_private_class (tree);
 static int method_name_cmp (const void *, const void *);
 static int resort_method_name_cmp (const void *, const void *);
-static void add_implicitly_declared_members (tree, int, int, int);
+static void add_implicitly_declared_members (tree, int, int);
 static tree fixed_type_or_null (tree, int *, int *);
 static tree resolve_address_of_overloaded_function (tree, tree, tsubst_flags_t,
                                                    bool, tree);
@@ -134,13 +142,13 @@ static tree build_vtbl_initializer (tree, tree, tree, tree, int *);
 static int count_fields (tree);
 static int add_fields_to_record_type (tree, struct sorted_fields_type*, int);
 static void check_bitfield_decl (tree);
-static void check_field_decl (tree, tree, int *, int *, int *, int *);
-static void check_field_decls (tree, tree *, int *, int *, int *);
+static void check_field_decl (tree, tree, int *, int *, int *);
+static void check_field_decls (tree, tree *, int *, int *);
 static tree *build_base_field (record_layout_info, tree, splay_tree, tree *);
 static void build_base_fields (record_layout_info, splay_tree, tree *);
 static void check_methods (tree);
 static void remove_zero_width_bit_fields (tree);
-static void check_bases (tree, int *, int *, int *);
+static void check_bases (tree, int *, int *);
 static void check_bases_and_members (tree);
 static tree create_vtable_ptr (tree, tree *);
 static void include_empty_classes (record_layout_info);
@@ -155,11 +163,11 @@ static void add_vcall_offset_vtbl_entries_1 (tree, vtbl_init_data *);
 static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
 static void add_vcall_offset (tree, tree, vtbl_init_data *);
 static void layout_vtable_decl (tree, int);
-static tree dfs_find_final_overrider (tree, void *);
+static tree dfs_find_final_overrider_pre (tree, void *);
 static tree dfs_find_final_overrider_post (tree, void *);
-static tree dfs_find_final_overrider_q (tree, int, void *);
 static tree find_final_overrider (tree, tree, tree);
 static int make_new_vtable (tree, tree);
+static tree get_primary_binfo (tree);
 static int maybe_indent_hierarchy (FILE *, int, int);
 static tree dump_class_hierarchy_r (FILE *, int, tree, tree, int);
 static void dump_class_hierarchy (tree);
@@ -170,36 +178,32 @@ static void dump_vtt (tree, tree);
 static void dump_thunk (FILE *, int, tree);
 static tree build_vtable (tree, tree, tree);
 static void initialize_vtable (tree, tree);
-static void initialize_array (tree, tree);
 static void layout_nonempty_base_or_field (record_layout_info,
-                                                  tree, tree, splay_tree);
+                                          tree, tree, splay_tree);
 static tree end_of_class (tree, int);
 static bool layout_empty_base (tree, tree, splay_tree);
 static void accumulate_vtbl_inits (tree, tree, tree, tree, tree);
 static tree dfs_accumulate_vtbl_inits (tree, tree, tree, tree,
                                               tree);
 static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
-static void build_vcall_and_vbase_vtbl_entries (tree, 
-                                                       vtbl_init_data *);
+static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
 static void clone_constructors_and_destructors (tree);
 static tree build_clone (tree, tree);
 static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
-static tree copy_virtuals (tree);
 static void build_ctor_vtbl_group (tree, tree);
 static void build_vtt (tree);
 static tree binfo_ctor_vtable (tree);
 static tree *build_vtt_inits (tree, tree, tree *, tree *);
 static tree dfs_build_secondary_vptr_vtt_inits (tree, void *);
-static tree dfs_ctor_vtable_bases_queue_p (tree, int, void *data);
 static tree dfs_fixup_binfo_vtbls (tree, void *);
 static int record_subobject_offset (tree, tree, splay_tree);
 static int check_subobject_offset (tree, tree, splay_tree);
 static int walk_subobject_offsets (tree, subobject_offset_fn,
-                                          tree, splay_tree, tree, int);
-static void record_subobject_offsets (tree, tree, splay_tree, int);
+                                  tree, splay_tree, tree, int);
+static void record_subobject_offsets (tree, tree, splay_tree, bool);
 static int layout_conflict_p (tree, tree, splay_tree, int);
 static int splay_tree_compare_integer_csts (splay_tree_key k1,
-                                                   splay_tree_key k2);
+                                           splay_tree_key k2);
 static void warn_about_ambiguous_bases (tree);
 static bool type_requires_array_cookie (tree);
 static bool contains_empty_class_p (tree);
@@ -208,12 +212,6 @@ static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
 static tree end_of_base (tree);
 static tree get_vcall_index (tree, tree);
 
-/* Macros for dfs walking during vtt construction. See
-   dfs_ctor_vtable_bases_queue_p, dfs_build_secondary_vptr_vtt_inits
-   and dfs_fixup_binfo_vtbls.  */
-#define VTT_TOP_LEVEL_P(NODE) (TREE_LIST_CHECK (NODE)->common.unsigned_flag)
-#define VTT_MARKED_BINFO_P(NODE) TREE_USED (NODE)
-
 /* Variables shared between class.c and call.c.  */
 
 #ifdef GATHER_STATISTICS
@@ -238,9 +236,9 @@ int n_inner_fields_searched = 0;
 
 tree
 build_base_path (enum tree_code code,
-                 tree expr,
-                 tree binfo,
-                 int nonnull)
+                tree expr,
+                tree binfo,
+                int nonnull)
 {
   tree v_binfo = NULL_TREE;
   tree d_binfo = NULL_TREE;
@@ -270,19 +268,18 @@ build_base_path (enum tree_code code,
   if (want_pointer)
     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
 
-  gcc_assert (code == MINUS_EXPR
-             ? same_type_p (BINFO_TYPE (binfo), probe)
-             : code == PLUS_EXPR
-             ? same_type_p (BINFO_TYPE (d_binfo), probe)
-             : false);
-  
+  gcc_assert ((code == MINUS_EXPR
+              && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
+             || (code == PLUS_EXPR
+                 && SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe)));
+
   if (binfo == d_binfo)
     /* Nothing to do.  */
     return expr;
 
   if (code == MINUS_EXPR && v_binfo)
     {
-      error ("cannot convert from base `%T' to derived type `%T' via virtual base `%T'",
+      error ("cannot convert from base %qT to derived type %qT via virtual base %qT",
             BINFO_TYPE (binfo), BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
       return error_mark_node;
     }
@@ -293,13 +290,23 @@ build_base_path (enum tree_code code,
 
   offset = BINFO_OFFSET (binfo);
   fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
+  target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
 
   /* Do we need to look in the vtable for the real offset?  */
   virtual_access = (v_binfo && fixed_type_p <= 0);
 
   /* Do we need to check for a null pointer?  */
-  if (want_pointer && !nonnull && (virtual_access || !integer_zerop (offset)))
-    null_test = error_mark_node;
+  if (want_pointer && !nonnull)
+    {
+      /* If we know the conversion will not actually change the value
+        of EXPR, then we can avoid testing the expression for NULL.
+        We have to avoid generating a COMPONENT_REF for a base class
+        field, because other parts of the compiler know that such
+        expressions are always non-NULL.  */
+      if (!virtual_access && integer_zerop (offset))
+       return build_nop (build_pointer_type (target_type), expr);
+      null_test = error_mark_node;
+    }
 
   /* Protect against multiple evaluation if necessary.  */
   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
@@ -307,8 +314,11 @@ build_base_path (enum tree_code code,
 
   /* Now that we've saved expr, build the real null test.  */
   if (null_test)
-    null_test = fold (build2 (NE_EXPR, boolean_type_node,
-                             expr, integer_zero_node));
+    {
+      tree zero = cp_convert (TREE_TYPE (expr), integer_zero_node);
+      null_test = fold_build2 (NE_EXPR, boolean_type_node,
+                              expr, zero);
+    }
 
   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
   if (code == PLUS_EXPR && !virtual_access
@@ -319,7 +329,7 @@ build_base_path (enum tree_code code,
       expr = build_indirect_ref (expr, NULL);
       expr = build_simple_base_path (expr, binfo);
       if (want_pointer)
-       expr = build_unary_op (ADDR_EXPR, expr, 0);
+       expr = build_address (expr);
       target_type = TREE_TYPE (expr);
       goto out;
     }
@@ -327,31 +337,29 @@ build_base_path (enum tree_code code,
   if (virtual_access)
     {
       /* Going via virtual base V_BINFO.  We need the static offset
-         from V_BINFO to BINFO, and the dynamic offset from D_BINFO to
-         V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
+        from V_BINFO to BINFO, and the dynamic offset from D_BINFO to
+        V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
       tree v_offset;
 
       if (fixed_type_p < 0 && in_base_initializer)
        {
-         /* In a base member initializer, we cannot rely on
-            the vtable being set up. We have to use the vtt_parm.  */
-         tree derived = BINFO_INHERITANCE_CHAIN (v_binfo);
+         /* In a base member initializer, we cannot rely on the
+            vtable being set up.  We have to indirect via the
+            vtt_parm.  */
          tree t;
 
-         t = TREE_TYPE (TYPE_VFIELD (BINFO_TYPE (derived)));
+         t = TREE_TYPE (TYPE_VFIELD (current_class_type));
          t = build_pointer_type (t);
          v_offset = convert (t, current_vtt_parm);
-         v_offset = build2 (PLUS_EXPR, t, v_offset,
-                            BINFO_VPTR_INDEX (derived));
          v_offset = build_indirect_ref (v_offset, NULL);
        }
       else
        v_offset = build_vfield_ref (build_indirect_ref (expr, NULL),
                                     TREE_TYPE (TREE_TYPE (expr)));
-      
+
       v_offset = build2 (PLUS_EXPR, TREE_TYPE (v_offset),
                         v_offset,  BINFO_VPTR_FIELD (v_binfo));
-      v_offset = build1 (NOP_EXPR, 
+      v_offset = build1 (NOP_EXPR,
                         build_pointer_type (ptrdiff_type_node),
                         v_offset);
       v_offset = build_indirect_ref (v_offset, NULL);
@@ -359,7 +367,7 @@ build_base_path (enum tree_code code,
       TREE_INVARIANT (v_offset) = 1;
 
       offset = convert_to_integer (ptrdiff_type_node,
-                                  size_diffop (offset, 
+                                  size_diffop (offset,
                                                BINFO_OFFSET (v_binfo)));
 
       if (!integer_zerop (offset))
@@ -373,34 +381,33 @@ build_base_path (enum tree_code code,
                         build2 (EQ_EXPR, boolean_type_node,
                                 current_in_charge_parm, integer_zero_node),
                         v_offset,
-                        BINFO_OFFSET (binfo));
+                        convert_to_integer (ptrdiff_type_node,
+                                            BINFO_OFFSET (binfo)));
       else
        offset = v_offset;
     }
 
-  target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
-  
   target_type = cp_build_qualified_type
     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
   ptr_target_type = build_pointer_type (target_type);
   if (want_pointer)
     target_type = ptr_target_type;
-  
+
   expr = build1 (NOP_EXPR, ptr_target_type, expr);
 
   if (!integer_zerop (offset))
     expr = build2 (code, ptr_target_type, expr, offset);
   else
     null_test = NULL;
-  
+
   if (!want_pointer)
     expr = build_indirect_ref (expr, NULL);
 
  out:
   if (null_test)
-    expr = fold (build3 (COND_EXPR, target_type, null_test, expr,
-                        fold (build1 (NOP_EXPR, target_type,
-                                      integer_zero_node))));
+    expr = fold_build3 (COND_EXPR, target_type, null_test, expr,
+                       fold_build1 (NOP_EXPR, target_type,
+                                    integer_zero_node));
 
   return expr;
 }
@@ -418,8 +425,18 @@ build_simple_base_path (tree expr, tree binfo)
 
   if (d_binfo == NULL_TREE)
     {
-      if (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) != type)
-       abort ();
+      tree temp;
+
+      gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type);
+
+      /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x'
+        into `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only
+        an lvalue in the frontend; only _DECLs and _REFs are lvalues
+        in the backend.  */
+      temp = unary_complex_lvalue (ADDR_EXPR, expr);
+      if (temp)
+       expr = build_indirect_ref (temp, NULL);
+
       return expr;
     }
 
@@ -432,33 +449,64 @@ build_simple_base_path (tree expr, tree binfo)
     if (TREE_CODE (field) == FIELD_DECL
        && DECL_FIELD_IS_BASE (field)
        && TREE_TYPE (field) == type)
-      return build_class_member_access_expr (expr, field,
-                                            NULL_TREE, false);
+      {
+       /* We don't use build_class_member_access_expr here, as that
+          has unnecessary checks, and more importantly results in
+          recursive calls to dfs_walk_once.  */
+       int type_quals = cp_type_quals (TREE_TYPE (expr));
+
+       expr = build3 (COMPONENT_REF,
+                      cp_build_qualified_type (type, type_quals),
+                      expr, field, NULL_TREE);
+       expr = fold_if_not_in_template (expr);
+
+       /* Mark the expression const or volatile, as appropriate.
+          Even though we've dealt with the type above, we still have
+          to mark the expression itself.  */
+       if (type_quals & TYPE_QUAL_CONST)
+         TREE_READONLY (expr) = 1;
+       if (type_quals & TYPE_QUAL_VOLATILE)
+         TREE_THIS_VOLATILE (expr) = 1;
+
+       return expr;
+      }
 
   /* Didn't find the base field?!?  */
-  abort ();
+  gcc_unreachable ();
 }
 
-/* Convert OBJECT to the base TYPE.  If CHECK_ACCESS is true, an error
-   message is emitted if TYPE is inaccessible.  OBJECT is assumed to
-   be non-NULL.  */
+/* Convert OBJECT to the base TYPE.  OBJECT is an expression whose
+   type is a class type or a pointer to a class type.  In the former
+   case, TYPE is also a class type; in the latter it is another
+   pointer type.  If CHECK_ACCESS is true, an error message is emitted
+   if TYPE is inaccessible.  If OBJECT has pointer type, the value is
+   assumed to be non-NULL.  */
 
 tree
-convert_to_base (tree object, tree type, bool check_access)
+convert_to_base (tree object, tree type, bool check_access, bool nonnull)
 {
   tree binfo;
+  tree object_type;
+
+  if (TYPE_PTR_P (TREE_TYPE (object)))
+    {
+      object_type = TREE_TYPE (TREE_TYPE (object));
+      type = TREE_TYPE (type);
+    }
+  else
+    object_type = TREE_TYPE (object);
 
-  binfo = lookup_base (TREE_TYPE (object), type, 
-                      check_access ? ba_check : ba_ignore, 
+  binfo = lookup_base (object_type, type,
+                      check_access ? ba_check : ba_unique,
                       NULL);
   if (!binfo || binfo == error_mark_node)
     return error_mark_node;
 
-  return build_base_path (PLUS_EXPR, object, binfo, /*nonnull=*/1);
+  return build_base_path (PLUS_EXPR, object, binfo, nonnull);
 }
 
-/* EXPR is an expression with class type.  BASE is a base class (a
-   BINFO) of that class type.  Returns EXPR, converted to the BASE
+/* EXPR is an expression with unqualified class type.  BASE is a base
+   binfo of that class type.  Returns EXPR, converted to the BASE
    type.  This function assumes that EXPR is the most derived class;
    therefore virtual bases can be found at their static offsets.  */
 
@@ -468,14 +516,14 @@ convert_to_base_statically (tree expr, tree base)
   tree expr_type;
 
   expr_type = TREE_TYPE (expr);
-  if (!same_type_p (expr_type, BINFO_TYPE (base)))
+  if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     {
       tree pointer_type;
 
       pointer_type = build_pointer_type (expr_type);
       expr = build_unary_op (ADDR_EXPR, expr, /*noconvert=*/1);
       if (!integer_zerop (BINFO_OFFSET (base)))
-         expr = build2 (PLUS_EXPR, pointer_type, expr, 
+         expr = build2 (PLUS_EXPR, pointer_type, expr,
                         build_nop (pointer_type, BINFO_OFFSET (base)));
       expr = build_nop (build_pointer_type (BINFO_TYPE (base)), expr);
       expr = build1 (INDIRECT_REF, BINFO_TYPE (base), expr);
@@ -485,6 +533,36 @@ convert_to_base_statically (tree expr, tree base)
 }
 
 \f
+tree
+build_vfield_ref (tree datum, tree type)
+{
+  tree vfield, vcontext;
+
+  if (datum == error_mark_node)
+    return error_mark_node;
+
+  /* First, convert to the requested type.  */
+  if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
+    datum = convert_to_base (datum, type, /*check_access=*/false,
+                            /*nonnull=*/true);
+
+  /* Second, the requested type may not be the owner of its own vptr.
+     If not, convert to the base class that owns it.  We cannot use
+     convert_to_base here, because VCONTEXT may appear more than once
+     in the inheritance hierarchy of TYPE, and thus direct conversion
+     between the types may be ambiguous.  Following the path back up
+     one step at a time via primary bases avoids the problem.  */
+  vfield = TYPE_VFIELD (type);
+  vcontext = DECL_CONTEXT (vfield);
+  while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
+    {
+      datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
+      type = TREE_TYPE (datum);
+    }
+
+  return build3 (COMPONENT_REF, TREE_TYPE (vfield), datum, vfield, NULL_TREE);
+}
+
 /* Given an object INSTANCE, return an expression which yields the
    vtable element corresponding to INDEX.  There are many special
    cases for INSTANCE which we take care of here, mainly to avoid
@@ -507,14 +585,14 @@ build_vtbl_ref_1 (tree instance, tree idx)
   if (fixed_type && !cdtorp)
     {
       tree binfo = lookup_base (fixed_type, basetype,
-                               ba_ignore|ba_quiet, NULL);
+                               ba_unique | ba_quiet, NULL);
       if (binfo)
        vtbl = unshare_expr (BINFO_VTABLE (binfo));
     }
 
   if (!vtbl)
     vtbl = build_vfield_ref (instance, basetype);
-  
+
   assemble_external (vtbl);
 
   aref = build_array_ref (vtbl, idx);
@@ -563,15 +641,6 @@ get_vtable_name (tree type)
   return mangle_vtbl_for_type (type);
 }
 
-/* Return an IDENTIFIER_NODE for the name of the virtual table table
-   for TYPE.  */
-
-tree
-get_vtt_name (tree type)
-{
-  return mangle_vtt_for_type (type);
-}
-
 /* DECL is an entity associated with TYPE, like a virtual table or an
    implicitly generated constructor.  Determine whether or not DECL
    should have external or internal linkage at the object file
@@ -627,28 +696,27 @@ build_vtable (tree class_type, tree name, tree vtable_type)
   DECL_EXTERNAL (decl) = 1;
   DECL_NOT_REALLY_EXTERN (decl) = 1;
 
-  if (write_symbols == DWARF2_DEBUG)
-    /* Mark the VAR_DECL node representing the vtable itself as a
-       "gratuitous" one, thereby forcing dwarfout.c to ignore it.  It
-       is rather important that such things be ignored because any
-       effort to actually generate DWARF for them will run into
-       trouble when/if we encounter code like:
-       
-         #pragma interface
-        struct S { virtual void member (); };
-          
-       because the artificial declaration of the vtable itself (as
-       manufactured by the g++ front end) will say that the vtable is
-       a static member of `S' but only *after* the debug output for
-       the definition of `S' has already been output.  This causes
-       grief because the DWARF entry for the definition of the vtable
-       will try to refer back to an earlier *declaration* of the
-       vtable as a static member of `S' and there won't be one.  We
-       might be able to arrange to have the "vtable static member"
-       attached to the member list for `S' before the debug info for
-       `S' get written (which would solve the problem) but that would
-       require more intrusive changes to the g++ front end.  */
-    DECL_IGNORED_P (decl) = 1;
+  /* Mark the VAR_DECL node representing the vtable itself as a
+     "gratuitous" one, thereby forcing dwarfout.c to ignore it.  It
+     is rather important that such things be ignored because any
+     effort to actually generate DWARF for them will run into
+     trouble when/if we encounter code like:
+
+     #pragma interface
+     struct S { virtual void member (); };
+
+     because the artificial declaration of the vtable itself (as
+     manufactured by the g++ front end) will say that the vtable is
+     a static member of `S' but only *after* the debug output for
+     the definition of `S' has already been output.  This causes
+     grief because the DWARF entry for the definition of the vtable
+     will try to refer back to an earlier *declaration* of the
+     vtable as a static member of `S' and there won't be one.  We
+     might be able to arrange to have the "vtable static member"
+     attached to the member list for `S' before the debug info for
+     `S' get written (which would solve the problem) but that would
+     require more intrusive changes to the g++ front end.  */
+  DECL_IGNORED_P (decl) = 1;
 
   return decl;
 }
@@ -659,42 +727,26 @@ build_vtable (tree class_type, tree name, tree vtable_type)
    impossible to actually build the vtable, but is useful to get at those
    which are known to exist in the runtime.  */
 
-tree 
+tree
 get_vtable_decl (tree type, int complete)
 {
   tree decl;
 
   if (CLASSTYPE_VTABLES (type))
     return CLASSTYPE_VTABLES (type);
-  
+
   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
   CLASSTYPE_VTABLES (type) = decl;
 
   if (complete)
     {
       DECL_EXTERNAL (decl) = 1;
-      cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
+      finish_decl (decl, NULL_TREE, NULL_TREE);
     }
 
   return decl;
 }
 
-/* Returns a copy of the BINFO_VIRTUALS list in BINFO.  The
-   BV_VCALL_INDEX for each entry is cleared.  */
-
-static tree
-copy_virtuals (tree binfo)
-{
-  tree copies;
-  tree t;
-
-  copies = copy_list (BINFO_VIRTUALS (binfo));
-  for (t = copies; t; t = TREE_CHAIN (t))
-    BV_VCALL_INDEX (t) = NULL_TREE;
-
-  return copies;
-}
-
 /* Build the primary virtual function table for TYPE.  If BINFO is
    non-NULL, build the vtable starting with the initial approximation
    that it is the same as the one which is the head of the association
@@ -708,15 +760,15 @@ build_primary_vtable (tree binfo, tree type)
   tree virtuals;
 
   decl = get_vtable_decl (type, /*complete=*/0);
-  
+
   if (binfo)
     {
       if (BINFO_NEW_VTABLE_MARKED (binfo))
        /* We have already created a vtable for this base, so there's
           no need to do it again.  */
        return 0;
-      
-      virtuals = copy_virtuals (binfo);
+
+      virtuals = copy_list (BINFO_VIRTUALS (binfo));
       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
@@ -765,9 +817,9 @@ build_secondary_vtable (tree binfo)
   /* Remember that we've created a vtable for this BINFO, so that we
      don't try to do so again.  */
   SET_BINFO_NEW_VTABLE_MARKED (binfo);
-  
+
   /* Make fresh virtual list, so we can smash it later.  */
-  BINFO_VIRTUALS (binfo) = copy_virtuals (binfo);
+  BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
 
   /* Secondary vtables are laid out as part of the same structure as
      the primary vtable.  */
@@ -785,10 +837,7 @@ make_new_vtable (tree t, tree binfo)
     /* In this case, it is *type*'s vtable we are modifying.  We start
        with the approximation that its vtable is that of the
        immediate base class.  */
-    /* ??? This actually passes TYPE_BINFO (t), not the primary base binfo,
-       since we've updated DECL_CONTEXT (TYPE_VFIELD (t)) by now.  */
-    return build_primary_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))),
-                                t);
+    return build_primary_vtable (binfo, t);
   else
     /* This is our very own copy of `basetype' to play with.  Later,
        we will fill in all the virtual functions that override the
@@ -805,10 +854,10 @@ make_new_vtable (tree t, tree binfo)
 
 static void
 modify_vtable_entry (tree t,
-                     tree binfo, 
-                     tree fndecl, 
-                     tree delta, 
-                     tree *virtuals)
+                    tree binfo,
+                    tree fndecl,
+                    tree delta,
+                    tree *virtuals)
 {
   tree v;
 
@@ -836,27 +885,30 @@ modify_vtable_entry (tree t,
 }
 
 \f
-/* Add method METHOD to class TYPE.  */
+/* Add method METHOD to class TYPE.  If USING_DECL is non-null, it is
+   the USING_DECL naming METHOD.  Returns true if the method could be
+   added to the method vec.  */
 
-void
-add_method (tree type, tree method)
+bool
+add_method (tree type, tree method, tree using_decl)
 {
-  int using;
   unsigned slot;
   tree overload;
-  int template_conv_p;
-  VEC(tree) *method_vec;
+  bool template_conv_p = false;
+  bool conv_p;
+  VEC(tree,gc) *method_vec;
   bool complete_p;
   bool insert_p = false;
   tree current_fns;
 
   if (method == error_mark_node)
-    return;
+    return false;
 
   complete_p = COMPLETE_TYPE_P (type);
-  using = (DECL_CONTEXT (method) != type);
-  template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL
-                     && DECL_TEMPLATE_CONV_FN_P (method));
+  conv_p = DECL_CONV_FN_P (method);
+  if (conv_p)
+    template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL
+                      && DECL_TEMPLATE_CONV_FN_P (method));
 
   method_vec = CLASSTYPE_METHOD_VEC (type);
   if (!method_vec)
@@ -865,7 +917,7 @@ add_method (tree type, tree method)
         allocate at least two (for constructors and destructors), and
         we're going to end up with an assignment operator at some
         point as well.  */
-      method_vec = VEC_alloc (tree, 8);
+      method_vec = VEC_alloc (tree, gc, 8);
       /* Create slots for constructors and destructors.  */
       VEC_quick_push (tree, method_vec, NULL_TREE);
       VEC_quick_push (tree, method_vec, NULL_TREE);
@@ -878,22 +930,24 @@ add_method (tree type, tree method)
   else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method))
     {
       slot = CLASSTYPE_DESTRUCTOR_SLOT;
-      TYPE_HAS_DESTRUCTOR (type) = 1;
-      
+
       if (TYPE_FOR_JAVA (type))
-       error (DECL_ARTIFICIAL (method)
-              ? "Java class '%T' cannot have an implicit non-trivial destructor"
-              : "Java class '%T' cannot have a destructor",
-              DECL_CONTEXT (method));
+       {
+         if (!DECL_ARTIFICIAL (method))
+           error ("Java class %qT cannot have a destructor", type);
+         else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
+           error ("Java class %qT cannot have an implicit non-trivial "
+                  "destructor",
+                  type);
+       }
     }
   else
     {
-      bool conv_p = DECL_CONV_FN_P (method);
       tree m;
 
       insert_p = true;
       /* See if we already have an entry with this name.  */
-      for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; 
+      for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
           VEC_iterate (tree, method_vec, slot, m);
           ++slot)
        {
@@ -919,7 +973,7 @@ add_method (tree type, tree method)
        }
     }
   current_fns = insert_p ? NULL_TREE : VEC_index (tree, method_vec, slot);
-  
+
   if (processing_template_decl)
     /* TYPE is a template class.  Don't issue any errors now; wait
        until instantiation time to complain.  */
@@ -932,9 +986,10 @@ add_method (tree type, tree method)
       for (fns = current_fns; fns; fns = OVL_NEXT (fns))
        {
          tree fn = OVL_CURRENT (fns);
+         tree fn_type;
+         tree method_type;
          tree parms1;
          tree parms2;
-         bool same = 1;
 
          if (TREE_CODE (fn) != TREE_CODE (method))
            continue;
@@ -949,8 +1004,10 @@ add_method (tree type, tree method)
             functions in the derived class override and/or hide member
             functions with the same name and parameter types in a base
             class (rather than conflicting).  */
-         parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
-         parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
+         fn_type = TREE_TYPE (fn);
+         method_type = TREE_TYPE (method);
+         parms1 = TYPE_ARG_TYPES (fn_type);
+         parms2 = TYPE_ARG_TYPES (method_type);
 
          /* Compare the quals on the 'this' parm.  Don't compare
             the whole types, as used functions are treated as
@@ -959,54 +1016,70 @@ add_method (tree type, tree method)
              && ! DECL_STATIC_FUNCTION_P (method)
              && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
                  != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
-           same = 0;
-         
-         /* For templates, the template parms must be identical.  */
+           continue;
+
+         /* For templates, the return type and template parameters
+            must be identical.  */
          if (TREE_CODE (fn) == TEMPLATE_DECL
-             && !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
-                                      DECL_TEMPLATE_PARMS (method)))
-           same = 0;
-         
+             && (!same_type_p (TREE_TYPE (fn_type),
+                               TREE_TYPE (method_type))
+                 || !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
+                                          DECL_TEMPLATE_PARMS (method))))
+           continue;
+
          if (! DECL_STATIC_FUNCTION_P (fn))
            parms1 = TREE_CHAIN (parms1);
          if (! DECL_STATIC_FUNCTION_P (method))
            parms2 = TREE_CHAIN (parms2);
 
-         if (same && compparms (parms1, parms2) 
-             && (!DECL_CONV_FN_P (fn) 
-                 || same_type_p (TREE_TYPE (TREE_TYPE (fn)),
-                                 TREE_TYPE (TREE_TYPE (method)))))
+         if (compparms (parms1, parms2)
+             && (!DECL_CONV_FN_P (fn)
+                 || same_type_p (TREE_TYPE (fn_type),
+                                 TREE_TYPE (method_type))))
            {
-             if (using && DECL_CONTEXT (fn) == type)
-               /* Defer to the local function.  */
-               return;
+             if (using_decl)
+               {
+                 if (DECL_CONTEXT (fn) == type)
+                   /* Defer to the local function.  */
+                   return false;
+                 if (DECL_CONTEXT (fn) == DECL_CONTEXT (method))
+                   error ("repeated using declaration %q+D", using_decl);
+                 else
+                   error ("using declaration %q+D conflicts with a previous using declaration",
+                          using_decl);
+               }
              else
                {
-                 cp_error_at ("`%#D' and `%#D' cannot be overloaded",
-                              method, fn);
-
-                 /* We don't call duplicate_decls here to merge
-                    the declarations because that will confuse
-                    things if the methods have inline
-                    definitions.  In particular, we will crash
-                    while processing the definitions.  */
-                 return;
+                 error ("%q+#D cannot be overloaded", method);
+                 error ("with %q+#D", fn);
                }
+
+             /* We don't call duplicate_decls here to merge the
+                declarations because that will confuse things if the
+                methods have inline definitions.  In particular, we
+                will crash while processing the definitions.  */
+             return false;
            }
        }
     }
 
-  /* Add the new binding.  */ 
+  /* A class should never have more than one destructor.  */ 
+  if (current_fns && DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (method))
+    return false;
+
+  /* Add the new binding.  */
   overload = build_overload (method, current_fns);
-  
-  if (slot >= CLASSTYPE_FIRST_CONVERSION_SLOT && !complete_p)
+
+  if (conv_p)
+    TYPE_HAS_CONVERSION (type) = 1;
+  else if (slot >= CLASSTYPE_FIRST_CONVERSION_SLOT && !complete_p)
     push_class_level_binding (DECL_NAME (method), overload);
 
   if (insert_p)
     {
       /* We only expect to add few methods in the COMPLETE_P case, so
         just make room for one more method in that case.  */
-      if (VEC_reserve (tree, method_vec, complete_p ? 1 : -1))
+      if (VEC_reserve (tree, gc, method_vec, complete_p ? -1 : 1))
        CLASSTYPE_METHOD_VEC (type) = method_vec;
       if (slot == VEC_length (tree, method_vec))
        VEC_quick_push (tree, method_vec, overload);
@@ -1014,8 +1087,9 @@ add_method (tree type, tree method)
        VEC_quick_insert (tree, method_vec, slot, overload);
     }
   else
-    /* Replace the current slot. */
+    /* Replace the current slot.  */
     VEC_replace (tree, method_vec, slot, overload);
+  return true;
 }
 
 /* Subroutines of finish_struct.  */
@@ -1039,9 +1113,10 @@ alter_access (tree t, tree fdecl, tree access)
       if (TREE_VALUE (elem) != access)
        {
          if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
-           cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
+           error ("conflicting access specifications for method"
+                  " %q+D, ignored", TREE_TYPE (fdecl));
          else
-           error ("conflicting access specifications for field `%E', ignored",
+           error ("conflicting access specifications for field %qE, ignored",
                   DECL_NAME (fdecl));
        }
       else
@@ -1065,52 +1140,16 @@ alter_access (tree t, tree fdecl, tree access)
 static void
 handle_using_decl (tree using_decl, tree t)
 {
-  tree ctype = DECL_INITIAL (using_decl);
+  tree decl = USING_DECL_DECLS (using_decl);
   tree name = DECL_NAME (using_decl);
   tree access
     = TREE_PRIVATE (using_decl) ? access_private_node
     : TREE_PROTECTED (using_decl) ? access_protected_node
     : access_public_node;
-  tree fdecl, binfo;
   tree flist = NULL_TREE;
   tree old_value;
 
-  if (ctype == error_mark_node)
-    return;
-
-  binfo = lookup_base (t, ctype, ba_any, NULL);
-  if (! binfo)
-    {
-      location_t saved_loc = input_location;
-
-      input_location = DECL_SOURCE_LOCATION (using_decl);
-      error_not_base_type (ctype, t);
-      input_location = saved_loc;
-      return;
-    }
-  
-  if (constructor_name_p (name, ctype))
-    {
-      cp_error_at ("`%D' names constructor", using_decl);
-      return;
-    }
-  if (constructor_name_p (name, t))
-    {
-      cp_error_at ("`%D' invalid in `%T'", using_decl, t);
-      return;
-    }
-
-  fdecl = lookup_member (binfo, name, 0, false);
-  
-  if (!fdecl)
-    {
-      cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
-      return;
-    }
-
-  if (BASELINK_P (fdecl))
-    /* Ignore base type this came from.  */
-    fdecl = BASELINK_FUNCTIONS (fdecl);
+  gcc_assert (!processing_template_decl && decl);
 
   old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false);
   if (old_value)
@@ -1124,8 +1163,10 @@ handle_using_decl (tree using_decl, tree t)
        old_value = NULL_TREE;
     }
 
-  if (is_overloaded_fn (fdecl))
-    flist = fdecl;
+  cp_emit_debug_info_for_using (decl, USING_DECL_SCOPE (using_decl));
+
+  if (is_overloaded_fn (decl))
+    flist = decl;
 
   if (! old_value)
     ;
@@ -1136,40 +1177,38 @@ handle_using_decl (tree using_decl, tree t)
           the same name already present in the current class.  */;
       else
        {
-         cp_error_at ("`%D' invalid in `%#T'", using_decl, t);
-         cp_error_at ("  because of local method `%#D' with same name",
-                      OVL_CURRENT (old_value));
+         error ("%q+D invalid in %q#T", using_decl, t);
+         error ("  because of local method %q+#D with same name",
+                OVL_CURRENT (old_value));
          return;
        }
     }
   else if (!DECL_ARTIFICIAL (old_value))
     {
-      cp_error_at ("`%D' invalid in `%#T'", using_decl, t);
-      cp_error_at ("  because of local member `%#D' with same name", old_value);
+      error ("%q+D invalid in %q#T", using_decl, t);
+      error ("  because of local member %q+#D with same name", old_value);
       return;
     }
-  
+
   /* Make type T see field decl FDECL with access ACCESS.  */
   if (flist)
     for (; flist; flist = OVL_NEXT (flist))
       {
-       add_method (t, OVL_CURRENT (flist));
+       add_method (t, OVL_CURRENT (flist), using_decl);
        alter_access (t, OVL_CURRENT (flist), access);
       }
   else
-    alter_access (t, fdecl, access);
+    alter_access (t, decl, access);
 }
 \f
-/* Run through the base classes of T, updating
-   CANT_HAVE_DEFAULT_CTOR_P, CANT_HAVE_CONST_CTOR_P, and
-   NO_CONST_ASN_REF_P.  Also set flag bits in T based on properties of
-   the bases.  */
+/* Run through the base classes of T, updating CANT_HAVE_CONST_CTOR_P,
+   and NO_CONST_ASN_REF_P.  Also set flag bits in T based on
+   properties of the bases.  */
 
 static void
 check_bases (tree t,
-             int* cant_have_default_ctor_p,
-             int* cant_have_const_ctor_p,
-             int* no_const_asn_ref_p)
+            int* cant_have_const_ctor_p,
+            int* no_const_asn_ref_p)
 {
   int i;
   int seen_non_virtual_nearly_empty_base_p;
@@ -1184,14 +1223,13 @@ check_bases (tree t,
       tree basetype = TREE_TYPE (base_binfo);
 
       gcc_assert (COMPLETE_TYPE_P (basetype));
-      
+
       /* Effective C++ rule 14.  We only need to check TYPE_POLYMORPHIC_P
         here because the case of virtual functions but non-virtual
         dtor is handled in finish_struct_1.  */
-      if (warn_ecpp && ! TYPE_POLYMORPHIC_P (basetype)
-         && TYPE_HAS_DESTRUCTOR (basetype))
-       warning ("base class `%#T' has a non-virtual destructor",
-                   basetype);
+      if (!TYPE_POLYMORPHIC_P (basetype))
+       warning (OPT_Weffc__,
+                 "base class %q#T has a non-virtual destructor", basetype);
 
       /* If the base class doesn't have copy constructors or
         assignment operators that take const references, then the
@@ -1202,17 +1240,6 @@ check_bases (tree t,
       if (TYPE_HAS_ASSIGN_REF (basetype)
          && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
        *no_const_asn_ref_p = 1;
-      /* Similarly, if the base class doesn't have a default
-        constructor, then the derived class won't have an
-        automatically generated default constructor.  */
-      if (TYPE_HAS_CONSTRUCTOR (basetype)
-         && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
-       {
-         *cant_have_default_ctor_p = 1;
-         if (! TYPE_HAS_CONSTRUCTOR (t))
-            pedwarn ("base `%T' with only non-default constructor in class without a constructor",
-                        basetype);
-       }
 
       if (BINFO_VIRTUAL_P (base_binfo))
        /* A virtual base does not effect nearly emptiness.  */
@@ -1235,13 +1262,13 @@ check_bases (tree t,
       /* A lot of properties from the bases also apply to the derived
         class.  */
       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
-      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) 
+      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
        |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
-      TYPE_HAS_COMPLEX_ASSIGN_REF (t) 
+      TYPE_HAS_COMPLEX_ASSIGN_REF (t)
        |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
       TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
-      CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) 
+      CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
        |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
     }
 }
@@ -1249,7 +1276,7 @@ check_bases (tree t,
 /* Determine all the primary bases within T.  Sets BINFO_PRIMARY_BASE_P for
    those that are primaries.  Sets BINFO_LOST_PRIMARY_P for those
    that have had a nearly-empty virtual primary base stolen by some
-   other base in the heirarchy.  Determines CLASSTYPE_PRIMARY_BASE for
+   other base in the hierarchy.  Determines CLASSTYPE_PRIMARY_BASE for
    T.  */
 
 static void
@@ -1272,9 +1299,10 @@ determine_primary_bases (tree t)
        {
          tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
          tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
-         
+
          if (parent_primary
-             && BINFO_TYPE (base_binfo) == BINFO_TYPE (parent_primary))
+             && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
+                                   BINFO_TYPE (parent_primary)))
            /* We are the primary binfo.  */
            BINFO_PRIMARY_P (base_binfo) = 1;
        }
@@ -1290,18 +1318,18 @@ determine_primary_bases (tree t)
          else
            {
              tree delta;
-             
+
              BINFO_PRIMARY_P (this_primary) = 1;
              BINFO_INHERITANCE_CHAIN (this_primary) = base_binfo;
-             
+
              /* A virtual binfo might have been copied from within
-                another hierarchy. As we're about to use it as a
-                primary base, make sure the offsets match.  */
+                another hierarchy. As we're about to use it as a
+                primary base, make sure the offsets match.  */
              delta = size_diffop (convert (ssizetype,
                                            BINFO_OFFSET (base_binfo)),
                                   convert (ssizetype,
                                            BINFO_OFFSET (this_primary)));
-         
+
              propagate_binfo_offsets (this_primary, delta);
            }
        }
@@ -1322,7 +1350,7 @@ determine_primary_bases (tree t)
   /* A "nearly-empty" virtual base class can be the primary base
      class, if no non-virtual polymorphic base can be found.  Look for
      a nearly-empty virtual dynamic base that is not already a primary
-     base of something in the heirarchy.  If there is no such base,
+     base of something in the hierarchy.  If there is no such base,
      just pick the first nearly-empty virtual base.  */
 
   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
@@ -1340,13 +1368,13 @@ determine_primary_bases (tree t)
          /* Remember the first candidate.  */
          primary = base_binfo;
       }
-  
+
  found:
   /* If we've got a primary base, use it.  */
   if (primary)
     {
       tree basetype = BINFO_TYPE (primary);
-      
+
       CLASSTYPE_PRIMARY_BINFO (t) = primary;
       if (BINFO_PRIMARY_P (primary))
        /* We are stealing a primary base.  */
@@ -1358,16 +1386,16 @@ determine_primary_bases (tree t)
 
          BINFO_INHERITANCE_CHAIN (primary) = type_binfo;
          /* A virtual binfo might have been copied from within
-            another hierarchy. As we're about to use it as a primary
-            base, make sure the offsets match.  */
+            another hierarchy. As we're about to use it as a primary
+            base, make sure the offsets match.  */
          delta = size_diffop (ssize_int (0),
                               convert (ssizetype, BINFO_OFFSET (primary)));
-         
+
          propagate_binfo_offsets (primary, delta);
        }
-      
+
       primary = TYPE_BINFO (basetype);
-      
+
       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
@@ -1381,7 +1409,7 @@ static void
 finish_struct_bits (tree t)
 {
   tree variants;
-  
+
   /* Fix up variants (if any).  */
   for (variants = TYPE_NEXT_VARIANT (t);
        variants;
@@ -1390,17 +1418,12 @@ finish_struct_bits (tree t)
       /* These fields are in the _TYPE part of the node, not in
         the TYPE_LANG_SPECIFIC component, so they are not shared.  */
       TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
-      TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
       TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
-      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants) 
+      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants)
        = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
 
-      TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (variants) 
-       = TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t);
       TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
-      TYPE_USES_VIRTUAL_BASECLASSES (variants)
-       = TYPE_USES_VIRTUAL_BASECLASSES (t);
-      
+
       TYPE_BINFO (variants) = TYPE_BINFO (t);
 
       /* Copy whatever these are holding today.  */
@@ -1412,8 +1435,8 @@ finish_struct_bits (tree t)
     }
 
   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t))
-    /* For a class w/o baseclasses, `finish_struct' has set
-       CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by definition).
+    /* For a class w/o baseclasses, 'finish_struct' has set
+       CLASSTYPE_PURE_VIRTUALS correctly (by definition).
        Similarly for a class whose base classes do not have vtables.
        When neither of these is true, we might have removed abstract
        virtuals (by providing a definition), added some (by declaring
@@ -1439,7 +1462,7 @@ finish_struct_bits (tree t)
 }
 
 /* Issue warnings about T having private constructors, but no friends,
-   and so forth.  
+   and so forth.
 
    HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
    static members.  HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
@@ -1460,10 +1483,10 @@ maybe_warn_about_overly_private_class (tree t)
       /* We will have warned when the template was declared; there's
         no need to warn on every instantiation.  */
       || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
-    /* There's no reason to even consider warning about this 
+    /* There's no reason to even consider warning about this
        class.  */
     return;
-    
+
   /* We only issue one warning, if more than one applies, because
      otherwise, on code like:
 
@@ -1483,25 +1506,25 @@ maybe_warn_about_overly_private_class (tree t)
   for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
     /* We're not interested in compiler-generated methods; they don't
        provide any way to call private members.  */
-    if (!DECL_ARTIFICIAL (fn)) 
+    if (!DECL_ARTIFICIAL (fn))
       {
        if (!TREE_PRIVATE (fn))
          {
-           if (DECL_STATIC_FUNCTION_P (fn)) 
+           if (DECL_STATIC_FUNCTION_P (fn))
              /* A non-private static member function is just like a
                 friend; it can create and invoke private member
                 functions, and be accessed without a class
                 instance.  */
              return;
-               
+
            has_nonprivate_method = 1;
            /* Keep searching for a static member function.  */
          }
        else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
          has_member_fn = 1;
-      } 
+      }
 
-  if (!has_nonprivate_method && has_member_fn) 
+  if (!has_nonprivate_method && has_member_fn)
     {
       /* There are no non-private methods, and there's at least one
         private member function that isn't a constructor or
@@ -1511,16 +1534,17 @@ maybe_warn_about_overly_private_class (tree t)
         constructors/destructors.)  */
       unsigned i;
       tree binfo = TYPE_BINFO (t);
-      
+
       for (i = 0; i != BINFO_N_BASE_BINFOS (binfo); i++)
        if (BINFO_BASE_ACCESS (binfo, i) != access_private_node)
          {
            has_nonprivate_method = 1;
            break;
          }
-      if (!has_nonprivate_method) 
+      if (!has_nonprivate_method)
        {
-         warning ("all member functions in class `%T' are private", t);
+         warning (OPT_Wctor_dtor_privacy,
+                   "all member functions in class %qT are private", t);
          return;
        }
     }
@@ -1528,32 +1552,36 @@ maybe_warn_about_overly_private_class (tree t)
   /* Even if some of the member functions are non-private, the class
      won't be useful for much if all the constructors or destructors
      are private: such an object can never be created or destroyed.  */
-  if (TYPE_HAS_DESTRUCTOR (t)
-      && TREE_PRIVATE (CLASSTYPE_DESTRUCTORS (t)))
+  fn = CLASSTYPE_DESTRUCTORS (t);
+  if (fn && TREE_PRIVATE (fn))
     {
-      warning ("`%#T' only defines a private destructor and has no friends",
+      warning (OPT_Wctor_dtor_privacy,
+               "%q#T only defines a private destructor and has no friends",
               t);
       return;
     }
 
-  if (TYPE_HAS_CONSTRUCTOR (t))
+  if (TYPE_HAS_CONSTRUCTOR (t)
+      /* Implicitly generated constructors are always public.  */
+      && (!CLASSTYPE_LAZY_DEFAULT_CTOR (t)
+         || !CLASSTYPE_LAZY_COPY_CTOR (t)))
     {
       int nonprivate_ctor = 0;
-         
+
       /* If a non-template class does not define a copy
         constructor, one is defined for it, enabling it to avoid
         this warning.  For a template class, this does not
         happen, and so we would normally get a warning on:
 
-          template <class T> class C { private: C(); };  
-         
+          template <class T> class C { private: C(); };
+
         To avoid this asymmetry, we check TYPE_HAS_INIT_REF.  All
         complete non-template or fully instantiated classes have this
         flag set.  */
       if (!TYPE_HAS_INIT_REF (t))
        nonprivate_ctor = 1;
-      else 
-       for (fn = CLASSTYPE_CONSTRUCTORS (t); fn; fn = OVL_NEXT (fn)) 
+      else
+       for (fn = CLASSTYPE_CONSTRUCTORS (t); fn; fn = OVL_NEXT (fn))
          {
            tree ctor = OVL_CURRENT (fn);
            /* Ideally, we wouldn't count copy constructors (or, in
@@ -1571,8 +1599,9 @@ maybe_warn_about_overly_private_class (tree t)
 
       if (nonprivate_ctor == 0)
        {
-         warning ("`%#T' only defines private constructors and has no friends",
-                     t);
+         warning (OPT_Wctor_dtor_privacy,
+                   "%q#T only defines private constructors and has no friends",
+                  t);
          return;
        }
     }
@@ -1588,9 +1617,9 @@ static struct {
 static int
 method_name_cmp (const void* m1_p, const void* m2_p)
 {
-  const tree *const m1 = m1_p;
-  const tree *const m2 = m2_p;
-  
+  const tree *const m1 = (const tree *) m1_p;
+  const tree *const m2 = (const tree *) m2_p;
+
   if (*m1 == NULL_TREE && *m2 == NULL_TREE)
     return 0;
   if (*m1 == NULL_TREE)
@@ -1608,8 +1637,8 @@ method_name_cmp (const void* m1_p, const void* m2_p)
 static int
 resort_method_name_cmp (const void* m1_p, const void* m2_p)
 {
-  const tree *const m1 = m1_p;
-  const tree *const m2 = m2_p;
+  const tree *const m1 = (const tree *) m1_p;
+  const tree *const m2 = (const tree *) m2_p;
   if (*m1 == NULL_TREE && *m2 == NULL_TREE)
     return 0;
   if (*m1 == NULL_TREE)
@@ -1629,13 +1658,13 @@ resort_method_name_cmp (const void* m1_p, const void* m2_p)
 
 /* Resort TYPE_METHOD_VEC because pointers have been reordered.  */
 
-void 
+void
 resort_type_method_vec (void* obj,
-                        void* orig_obj ATTRIBUTE_UNUSED ,
-                        gt_pointer_operator new_value,
-                        void* cookie)
+                       void* orig_obj ATTRIBUTE_UNUSED ,
+                       gt_pointer_operator new_value,
+                       void* cookie)
 {
-  VEC(tree) *method_vec = (VEC(tree) *) obj;
+  VEC(tree,gc) *method_vec = (VEC(tree,gc) *) obj;
   int len = VEC_length (tree, method_vec);
   size_t slot;
   tree fn;
@@ -1657,17 +1686,7 @@ resort_type_method_vec (void* obj,
     }
 }
 
-/* Warn about duplicate methods in fn_fields.  Also compact method
-   lists so that lookup can be made faster.
-
-   Data Structure: List of method lists.  The outer list is a
-   TREE_LIST, whose TREE_PURPOSE field is the field name and the
-   TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs.  TREE_CHAIN
-   links the entire list of methods for TYPE_METHODS.  Friends are
-   chained in the same way as member functions (? TREE_CHAIN or
-   DECL_CHAIN), but they live in the TREE_TYPE field of the outer
-   list.  That allows them to be quickly deleted, and requires no
-   extra storage.
+/* Warn about duplicate methods in fn_fields.
 
    Sort methods that are not special (i.e., constructors, destructors,
    and type conversion operators) so that we can find them faster in
@@ -1677,7 +1696,7 @@ static void
 finish_struct_methods (tree t)
 {
   tree fn_fields;
-  VEC(tree) *method_vec;
+  VEC(tree,gc) *method_vec;
   int slot, len;
 
   method_vec = CLASSTYPE_METHOD_VEC (t);
@@ -1686,18 +1705,11 @@ finish_struct_methods (tree t)
 
   len = VEC_length (tree, method_vec);
 
-  /* First fill in entry 0 with the constructors, entry 1 with destructors,
-     and the next few with type conversion operators (if any).  */
-  for (fn_fields = TYPE_METHODS (t); fn_fields; 
+  /* Clear DECL_IN_AGGR_P for all functions.  */
+  for (fn_fields = TYPE_METHODS (t); fn_fields;
        fn_fields = TREE_CHAIN (fn_fields))
-    /* Clear out this flag.  */
     DECL_IN_AGGR_P (fn_fields) = 0;
 
-  if (TYPE_HAS_DESTRUCTOR (t) && !CLASSTYPE_DESTRUCTORS (t))
-    /* We thought there was a destructor, but there wasn't.  Some
-       parse errors cause this anomalous situation.  */
-    TYPE_HAS_DESTRUCTOR (t) = 0;
-    
   /* Issue warnings about private constructors and such.  If there are
      no methods, then some public defaults are generated.  */
   maybe_warn_about_overly_private_class (t);
@@ -1724,7 +1736,7 @@ layout_vtable_decl (tree binfo, int n)
   tree atype;
   tree vtable;
 
-  atype = build_cplus_array_type (vtable_entry_type, 
+  atype = build_cplus_array_type (vtable_entry_type,
                                  build_index_type (size_int (n - 1)));
   layout_type (atype);
 
@@ -1775,7 +1787,7 @@ same_signature_p (tree fndecl, tree base_fndecl)
 
 /* Returns TRUE if DERIVED is a binfo containing the binfo BASE as a
    subobject.  */
+
 static bool
 base_derived_from (tree derived, tree base)
 {
@@ -1795,73 +1807,34 @@ base_derived_from (tree derived, tree base)
   return false;
 }
 
-typedef struct count_depth_data {
-  /* The depth of the current subobject, with "1" as the depth of the
-     most derived object in the hierarchy.  */
-  size_t depth;
-  /* The maximum depth found so far.  */
-  size_t max_depth;
-} count_depth_data;
-
-/* Called from find_final_overrider via dfs_walk.  */
-
-static tree
-dfs_depth_post (tree binfo ATTRIBUTE_UNUSED, void *data)
-{
-  count_depth_data *cd = (count_depth_data *) data;
-  if (cd->depth > cd->max_depth)
-    cd->max_depth = cd->depth;
-  cd->depth--;
-  return NULL_TREE;
-}
-
-/* Called from find_final_overrider via dfs_walk.  */
-
-static tree
-dfs_depth_q (tree derived, int i, void *data)
-{
-  count_depth_data *cd = (count_depth_data *) data;
-  cd->depth++;
-  return BINFO_BASE_BINFO (derived, i);
-}
-
 typedef struct find_final_overrider_data_s {
   /* The function for which we are trying to find a final overrider.  */
   tree fn;
   /* The base class in which the function was declared.  */
   tree declaring_base;
-  /* The most derived class in the hierarchy.  */
-  tree most_derived_type;
   /* The candidate overriders.  */
   tree candidates;
-  /* Each entry in this array is the next-most-derived class for a
-     virtual base class along the current path.  */
-  tree *vpath_list;
-  /* A pointer one past the top of the VPATH_LIST.  */
-  tree *vpath;
+  /* Path to most derived.  */
+  VEC(tree,heap) *path;
 } find_final_overrider_data;
 
 /* Add the overrider along the current path to FFOD->CANDIDATES.
    Returns true if an overrider was found; false otherwise.  */
 
 static bool
-dfs_find_final_overrider_1 (tree binfo, 
-                           tree *vpath, 
-                           find_final_overrider_data *ffod)
+dfs_find_final_overrider_1 (tree binfo,
+                           find_final_overrider_data *ffod,
+                           unsigned depth)
 {
   tree method;
 
   /* If BINFO is not the most derived type, try a more derived class.
      A definition there will overrider a definition here.  */
-  if (!same_type_p (BINFO_TYPE (binfo), ffod->most_derived_type))
+  if (depth)
     {
-      tree derived;
-
-      if (BINFO_VIRTUAL_P (binfo))
-       derived = *--vpath;
-      else
-       derived = BINFO_INHERITANCE_CHAIN (binfo);
-      if (dfs_find_final_overrider_1 (derived, vpath, ffod))
+      depth--;
+      if (dfs_find_final_overrider_1
+         (VEC_index (tree, ffod->path, depth), ffod, depth))
        return true;
     }
 
@@ -1869,7 +1842,7 @@ dfs_find_final_overrider_1 (tree binfo,
   if (method)
     {
       tree *candidate = &ffod->candidates;
-      
+
       /* Remove any candidates overridden by this new function.  */
       while (*candidate)
        {
@@ -1883,7 +1856,7 @@ dfs_find_final_overrider_1 (tree binfo,
          else
            candidate = &TREE_CHAIN (*candidate);
        }
-      
+
       /* Add the new function.  */
       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
       return true;
@@ -1895,36 +1868,23 @@ dfs_find_final_overrider_1 (tree binfo,
 /* Called from find_final_overrider via dfs_walk.  */
 
 static tree
-dfs_find_final_overrider (tree binfo, void* data)
+dfs_find_final_overrider_pre (tree binfo, void *data)
 {
   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
 
   if (binfo == ffod->declaring_base)
-    dfs_find_final_overrider_1 (binfo, ffod->vpath, ffod);
+    dfs_find_final_overrider_1 (binfo, ffod, VEC_length (tree, ffod->path));
+  VEC_safe_push (tree, heap, ffod->path, binfo);
 
   return NULL_TREE;
 }
 
 static tree
-dfs_find_final_overrider_q (tree derived, int ix, void *data)
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  find_final_overrider_data *ffod = (find_final_overrider_data *) data;
-
-  if (BINFO_VIRTUAL_P (binfo))
-    *ffod->vpath++ = derived;
-  
-  return binfo;
-}
-
-static tree
-dfs_find_final_overrider_post (tree binfo, void *data)
+dfs_find_final_overrider_post (tree binfo ATTRIBUTE_UNUSED, void *data)
 {
   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
+  VEC_pop (tree, ffod->path);
 
-  if (BINFO_VIRTUAL_P (binfo))
-    ffod->vpath--;
-  
   return NULL_TREE;
 }
 
@@ -1937,7 +1897,6 @@ static tree
 find_final_overrider (tree derived, tree binfo, tree fn)
 {
   find_final_overrider_data ffod;
-  count_depth_data cd;
 
   /* Getting this right is a little tricky.  This is valid:
 
@@ -1945,7 +1904,7 @@ find_final_overrider (tree derived, tree binfo, tree fn)
        struct T { virtual void f (); };
        struct U : public S, public T { };
 
-     even though calling `f' in `U' is ambiguous.  But, 
+     even though calling `f' in `U' is ambiguous.  But,
 
        struct R { virtual void f(); };
        struct S : virtual public R { virtual void f (); };
@@ -1953,40 +1912,27 @@ find_final_overrider (tree derived, tree binfo, tree fn)
        struct U : public S, public T { };
 
      is not -- there's no way to decide whether to put `S::f' or
-     `T::f' in the vtable for `R'.  
-     
+     `T::f' in the vtable for `R'.
+
      The solution is to look at all paths to BINFO.  If we find
      different overriders along any two, then there is a problem.  */
   if (DECL_THUNK_P (fn))
     fn = THUNK_TARGET (fn);
 
   /* Determine the depth of the hierarchy.  */
-  cd.depth = 0;
-  cd.max_depth = 0;
-  dfs_walk (derived, dfs_depth_post, dfs_depth_q, &cd);
-
   ffod.fn = fn;
   ffod.declaring_base = binfo;
-  ffod.most_derived_type = BINFO_TYPE (derived);
   ffod.candidates = NULL_TREE;
-  ffod.vpath_list = (tree *) xcalloc (cd.max_depth, sizeof (tree));
-  ffod.vpath = ffod.vpath_list;
+  ffod.path = VEC_alloc (tree, heap, 30);
 
-  dfs_walk_real (derived,
-                dfs_find_final_overrider,
-                dfs_find_final_overrider_post,
-                dfs_find_final_overrider_q,
-                &ffod);
+  dfs_walk_all (derived, dfs_find_final_overrider_pre,
+               dfs_find_final_overrider_post, &ffod);
 
-  free (ffod.vpath_list);
+  VEC_free (tree, heap, ffod.path);
 
   /* If there was no winner, issue an error message.  */
   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
-    {
-      error ("no unique final overrider for `%D' in `%T'", fn, 
-            BINFO_TYPE (derived));
-      return error_mark_node;
-    }
+    return error_mark_node;
 
   return ffod.candidates;
 }
@@ -1997,7 +1943,7 @@ find_final_overrider (tree derived, tree binfo, tree fn)
 static tree
 get_vcall_index (tree fn, tree type)
 {
-  VEC (tree_pair_s) *indices = CLASSTYPE_VCALL_INDICES (type);
+  VEC(tree_pair_s,gc) *indices = CLASSTYPE_VCALL_INDICES (type);
   tree_pair_p p;
   unsigned ix;
 
@@ -2007,9 +1953,7 @@ get_vcall_index (tree fn, tree type)
       return p->value;
 
   /* There should always be an appropriate index.  */
-  abort ();
-
-  return NULL_TREE;
+  gcc_unreachable ();
 }
 
 /* Update an entry in the vtable for BINFO, which is in the hierarchy
@@ -2048,24 +1992,32 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
   /* Find the final overrider.  */
   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
   if (overrider == error_mark_node)
-    return;
+    {
+      error ("no unique final overrider for %qD in %qT", target_fn, t);
+      return;
+    }
   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
-  
+
   /* Check for adjusting covariant return types.  */
   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
   base_return = TREE_TYPE (TREE_TYPE (target_fn));
-  
+
   if (POINTER_TYPE_P (over_return)
       && TREE_CODE (over_return) == TREE_CODE (base_return)
       && CLASS_TYPE_P (TREE_TYPE (over_return))
-      && CLASS_TYPE_P (TREE_TYPE (base_return)))
+      && CLASS_TYPE_P (TREE_TYPE (base_return))
+      /* If the overrider is invalid, don't even try.  */
+      && !DECL_INVALID_OVERRIDER_P (overrider_target))
     {
       /* If FN is a covariant thunk, we must figure out the adjustment
-         to the final base FN was converting to. As OVERRIDER_TARGET might
-         also be converting to the return type of FN, we have to
-         combine the two conversions here.  */
+        to the final base FN was converting to. As OVERRIDER_TARGET might
+        also be converting to the return type of FN, we have to
+        combine the two conversions here.  */
       tree fixed_offset, virtual_offset;
-      
+
+      over_return = TREE_TYPE (over_return);
+      base_return = TREE_TYPE (base_return);
+
       if (DECL_THUNK_P (fn))
        {
          gcc_assert (DECL_RESULT_THUNK_P (fn));
@@ -2080,32 +2032,51 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
           overriding function. We will want the vbase offset from
           there.  */
        virtual_offset = binfo_for_vbase (BINFO_TYPE (virtual_offset),
-                                         TREE_TYPE (over_return));
-      else if (!same_type_p (TREE_TYPE (over_return),
-                            TREE_TYPE (base_return)))
+                                         over_return);
+      else if (!same_type_ignoring_top_level_qualifiers_p
+              (over_return, base_return))
        {
          /* There was no existing virtual thunk (which takes
-            precedence).  */
-         tree thunk_binfo;
-         base_kind kind;
-         
-         thunk_binfo = lookup_base (TREE_TYPE (over_return),
-                                    TREE_TYPE (base_return),
-                                    ba_check | ba_quiet, &kind);
-
-         if (thunk_binfo && (kind == bk_via_virtual
-                             || !BINFO_OFFSET_ZEROP (thunk_binfo)))
+            precedence).  So find the binfo of the base function's
+            return type within the overriding function's return type.
+            We cannot call lookup base here, because we're inside a
+            dfs_walk, and will therefore clobber the BINFO_MARKED
+            flags.  Fortunately we know the covariancy is valid (it
+            has already been checked), so we can just iterate along
+            the binfos, which have been chained in inheritance graph
+            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;
+
+         /* 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;
+
+         /* See if virtual inheritance is involved.  */
+         for (virtual_offset = thunk_binfo;
+              virtual_offset;
+              virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
+           if (BINFO_VIRTUAL_P (virtual_offset))
+             break;
+
+         if (virtual_offset
+             || (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
            {
              tree offset = convert (ssizetype, BINFO_OFFSET (thunk_binfo));
 
-             if (kind == bk_via_virtual)
+             if (virtual_offset)
                {
-                 /* We convert via virtual base. Find the virtual
-                    base and adjust the fixed offset to be from there.  */
-                 while (!BINFO_VIRTUAL_P (thunk_binfo))
-                   thunk_binfo = BINFO_INHERITANCE_CHAIN (thunk_binfo);
-
-                 virtual_offset = thunk_binfo;
+                 /* We convert via virtual base.  Adjust the fixed
+                    offset to be from there.  */
                  offset = size_diffop
                    (offset, convert
                     (ssizetype, BINFO_OFFSET (virtual_offset)));
@@ -2119,7 +2090,7 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
                fixed_offset = offset;
            }
        }
-      
+
       if (fixed_offset || virtual_offset)
        /* Replace the overriding function with a covariant thunk.  We
           will emit the overriding function in its own slot as
@@ -2129,7 +2100,7 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
     }
   else
     gcc_assert (!DECL_THUNK_P (fn));
-  
+
   /* Assume that we will produce a thunk that convert all the way to
      the final overrider, and not to an intermediate virtual base.  */
   virtual_base = NULL_TREE;
@@ -2140,8 +2111,8 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
     {
       /* If we find the final overrider, then we can stop
         walking.  */
-      if (same_type_p (BINFO_TYPE (b), 
-                      BINFO_TYPE (TREE_VALUE (overrider))))
+      if (SAME_BINFO_TYPE_P (BINFO_TYPE (b),
+                            BINFO_TYPE (TREE_VALUE (overrider))))
        break;
 
       /* If we find a virtual base, and we haven't yet found the
@@ -2157,33 +2128,33 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
   if (overrider_fn != overrider_target && !virtual_base)
     {
       /* The ABI specifies that a covariant thunk includes a mangling
-        for a this pointer adjustment.  This-adjusting thunks that
-        override a function from a virtual base have a vcall
-        adjustment.  When the virtual base in question is a primary
-        virtual base, we know the adjustments are zero, (and in the
-        non-covariant case, we would not use the thunk).
-        Unfortunately we didn't notice this could happen, when
-        designing the ABI and so never mandated that such a covariant
-        thunk should be emitted.  Because we must use the ABI mandated
-        name, we must continue searching from the binfo where we
-        found the most recent definition of the function, towards the
-        primary binfo which first introduced the function into the
-        vtable.  If that enters a virtual base, we must use a vcall
-        this-adjusting thunk.  Bleah! */
+        for a this pointer adjustment.  This-adjusting thunks that
+        override a function from a virtual base have a vcall
+        adjustment.  When the virtual base in question is a primary
+        virtual base, we know the adjustments are zero, (and in the
+        non-covariant case, we would not use the thunk).
+        Unfortunately we didn't notice this could happen, when
+        designing the ABI and so never mandated that such a covariant
+        thunk should be emitted.  Because we must use the ABI mandated
+        name, we must continue searching from the binfo where we
+        found the most recent definition of the function, towards the
+        primary binfo which first introduced the function into the
+        vtable.  If that enters a virtual base, we must use a vcall
+        this-adjusting thunk.  Bleah! */
       tree probe = first_defn;
 
       while ((probe = get_primary_binfo (probe))
             && (unsigned) list_length (BINFO_VIRTUALS (probe)) > ix)
        if (BINFO_VIRTUAL_P (probe))
          virtual_base = probe;
-      
+
       if (virtual_base)
        /* Even if we find a virtual base, the correct delta is
           between the overrider and the binfo we're building a vtable
           for.  */
        goto virtual_covariant;
     }
-  
+
   /* Compute the constant adjustment to the `this' pointer.  The
      `this' pointer, when this function is called, will point at BINFO
      (or one of its primary bases, which are at the same offset).  */
@@ -2210,8 +2181,10 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
 
   if (virtual_base)
-    BV_VCALL_INDEX (*virtuals) 
+    BV_VCALL_INDEX (*virtuals)
       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
+  else
+    BV_VCALL_INDEX (*virtuals) = NULL_TREE;
 }
 
 /* Called from modify_all_vtables via dfs_walk.  */
@@ -2220,38 +2193,41 @@ static tree
 dfs_modify_vtables (tree binfo, void* data)
 {
   tree t = (tree) data;
-  
-  if (/* There's no need to modify the vtable for a non-virtual
-         primary base; we're not going to use that vtable anyhow.
-        We do still need to do this for virtual primary bases, as they
-        could become non-primary in a construction vtable.  */
-      (!BINFO_PRIMARY_P (binfo) || BINFO_VIRTUAL_P (binfo))
-      /* Similarly, a base without a vtable needs no modification.  */
-      && TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo))
-      /* Don't do the primary vtable, if it's new.  */
-      && (BINFO_TYPE (binfo) != t || CLASSTYPE_HAS_PRIMARY_BASE_P (t)))
-    {
-      tree virtuals;
-      tree old_virtuals;
-      unsigned ix;
-      
-      make_new_vtable (t, binfo);
-      
-      /* Now, go through each of the virtual functions in the virtual
-        function table for BINFO.  Find the final overrider, and
-        update the BINFO_VIRTUALS list appropriately.  */
-      for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
-            old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
-          virtuals;
-          ix++, virtuals = TREE_CHAIN (virtuals),
-            old_virtuals = TREE_CHAIN (old_virtuals))
-       update_vtable_entry_for_fn (t, 
-                                   binfo, 
-                                   BV_FN (old_virtuals),
-                                   &virtuals, ix);
-    }
-
-  BINFO_MARKED (binfo) = 1;
+  tree virtuals;
+  tree old_virtuals;
+  unsigned ix;
+
+  if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+    /* A base without a vtable needs no modification, and its bases
+       are uninteresting.  */
+    return dfs_skip_bases;
+
+  if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
+      && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
+    /* Don't do the primary vtable, if it's new.  */
+    return NULL_TREE;
+
+  if (BINFO_PRIMARY_P (binfo) && !BINFO_VIRTUAL_P (binfo))
+    /* There's no need to modify the vtable for a non-virtual primary
+       base; we're not going to use that vtable anyhow.  We do still
+       need to do this for virtual primary bases, as they could become
+       non-primary in a construction vtable.  */
+    return NULL_TREE;
+
+  make_new_vtable (t, binfo);
+
+  /* Now, go through each of the virtual functions in the virtual
+     function table for BINFO.  Find the final overrider, and update
+     the BINFO_VIRTUALS list appropriately.  */
+  for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
+        old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
+       virtuals;
+       ix++, virtuals = TREE_CHAIN (virtuals),
+        old_virtuals = TREE_CHAIN (old_virtuals))
+    update_vtable_entry_for_fn (t,
+                               binfo,
+                               BV_FN (old_virtuals),
+                               &virtuals, ix);
 
   return NULL_TREE;
 }
@@ -2272,8 +2248,7 @@ modify_all_vtables (tree t, tree virtuals)
   tree *fnsp;
 
   /* Update all of the vtables.  */
-  dfs_walk (binfo, dfs_modify_vtables, unmarkedp, t);
-  dfs_walk (binfo, dfs_unmark, markedp, t);
+  dfs_walk_once (binfo, dfs_modify_vtables, NULL, t);
 
   /* Add virtual functions not already in our primary vtable. These
      will be both those introduced by this class, and those overridden
@@ -2344,14 +2319,14 @@ get_basefndecls (tree name, tree t)
    a method declared virtual in the base class, then
    mark this field as being virtual as well.  */
 
-static void
+void
 check_for_override (tree decl, tree ctype)
 {
   if (TREE_CODE (decl) == TEMPLATE_DECL)
     /* In [temp.mem] we have:
 
-         A specialization of a member function template does not
-         override a virtual function from a base class.  */
+        A specialization of a member function template does not
+        override a virtual function from a base class.  */
     return;
   if ((DECL_DESTRUCTOR_P (decl)
        || IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
@@ -2374,15 +2349,15 @@ check_for_override (tree decl, tree ctype)
 /* Warn about hidden virtual functions that are not overridden in t.
    We know that constructors and destructors don't apply.  */
 
-void
+static void
 warn_hidden (tree t)
 {
-  VEC(tree) *method_vec = CLASSTYPE_METHOD_VEC (t);
+  VEC(tree,gc) *method_vec = CLASSTYPE_METHOD_VEC (t);
   tree fns;
   size_t i;
 
   /* We go through each separately named virtual function.  */
-  for (i = CLASSTYPE_FIRST_CONVERSION_SLOT; 
+  for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
        VEC_iterate (tree, method_vec, i, fns);
        ++i)
     {
@@ -2420,8 +2395,8 @@ warn_hidden (tree t)
          if (DECL_VINDEX (fndecl))
            {
              tree *prev = &base_fndecls;
-             
-             while (*prev) 
+
+             while (*prev)
                /* If the method from the base class has the same
                   signature as the method from the derived class, it
                   has been overridden.  */
@@ -2434,11 +2409,11 @@ warn_hidden (tree t)
 
       /* Now give a warning for all base functions without overriders,
         as they are hidden.  */
-      while (base_fndecls) 
+      while (base_fndecls)
        {
          /* Here we know it is a hider, and no overrider exists.  */
-         cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
-         cp_warning_at ("  by `%D'", fns);
+         warning (0, "%q+D was hidden", TREE_VALUE (base_fndecls));
+         warning (0, "  by %q+D", fns);
          base_fndecls = TREE_CHAIN (base_fndecls);
        }
     }
@@ -2472,24 +2447,22 @@ finish_struct_anon (tree t)
                 though, so we explicitly tolerate that.  We use
                 TYPE_ANONYMOUS_P rather than ANON_AGGR_TYPE_P so that
                 we also allow unnamed types used for defining fields.  */
-             if (DECL_ARTIFICIAL (elt) 
+             if (DECL_ARTIFICIAL (elt)
                  && (!DECL_IMPLICIT_TYPEDEF_P (elt)
                      || TYPE_ANONYMOUS_P (TREE_TYPE (elt))))
                continue;
 
              if (TREE_CODE (elt) != FIELD_DECL)
                {
-                 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
-                                elt);
+                 pedwarn ("%q+#D invalid; an anonymous union can "
+                          "only have non-static data members", elt);
                  continue;
                }
 
              if (TREE_PRIVATE (elt))
-               cp_pedwarn_at ("private member `%#D' in anonymous union",
-                              elt);
+               pedwarn ("private member %q+#D in anonymous union", elt);
              else if (TREE_PROTECTED (elt))
-               cp_pedwarn_at ("protected member `%#D' in anonymous union",
-                              elt);
+               pedwarn ("protected member %q+#D in anonymous union", elt);
 
              TREE_PRIVATE (elt) = TREE_PRIVATE (field);
              TREE_PROTECTED (elt) = TREE_PROTECTED (field);
@@ -2502,7 +2475,7 @@ finish_struct_anon (tree t)
    will be used later during class template instantiation.
    When FRIEND_P is zero, T can be a static member data (VAR_DECL),
    a non-static member data (FIELD_DECL), a member function
-   (FUNCTION_DECL), a nested type (RECORD_TYPE, ENUM_TYPE), 
+   (FUNCTION_DECL), a nested type (RECORD_TYPE, ENUM_TYPE),
    a typedef (TYPE_DECL) or a member class template (TEMPLATE_DECL)
    When FRIEND_P is nonzero, T is either a friend class
    (RECORD_TYPE, TEMPLATE_DECL) or a friend function
@@ -2519,49 +2492,67 @@ maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
 }
 
 /* Create default constructors, assignment operators, and so forth for
-   the type indicated by T, if they are needed.
-   CANT_HAVE_DEFAULT_CTOR, CANT_HAVE_CONST_CTOR, and
-   CANT_HAVE_CONST_ASSIGNMENT are nonzero if, for whatever reason, the
-   class cannot have a default constructor, copy constructor taking a
-   const reference argument, or an assignment operator taking a const
-   reference, respectively.  If a virtual destructor is created, its
-   DECL is returned; otherwise the return value is NULL_TREE.  */
+   the type indicated by T, if they are needed.  CANT_HAVE_CONST_CTOR,
+   and CANT_HAVE_CONST_ASSIGNMENT are nonzero if, for whatever reason,
+   the class cannot have a default constructor, copy constructor
+   taking a const reference argument, or an assignment operator taking
+   a const reference, respectively.  */
 
 static void
-add_implicitly_declared_members (tree t, 
-                                 int cant_have_default_ctor,
+add_implicitly_declared_members (tree t,
                                 int cant_have_const_cctor,
                                 int cant_have_const_assignment)
 {
-  tree default_fn;
-  tree implicit_fns = NULL_TREE;
-  tree virtual_dtor = NULL_TREE;
-  tree *f;
-
   /* Destructor.  */
-  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t))
+  if (!CLASSTYPE_DESTRUCTORS (t))
     {
-      default_fn = implicitly_declare_fn (sfk_destructor, t, /*const_p=*/0);
-      check_for_override (default_fn, t);
-
-      /* If we couldn't make it work, then pretend we didn't need it.  */
-      if (default_fn == void_type_node)
-       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 0;
-      else
+      /* In general, we create destructors lazily.  */
+      CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
+      /* However, if the implicit destructor is non-trivial
+        destructor, we sometimes have to create it at this point.  */
+      if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
        {
-         TREE_CHAIN (default_fn) = implicit_fns;
-         implicit_fns = default_fn;
+         bool lazy_p = true;
+
+         if (TYPE_FOR_JAVA (t))
+           /* If this a Java class, any non-trivial destructor is
+              invalid, even if compiler-generated.  Therefore, if the
+              destructor is non-trivial we create it now.  */
+           lazy_p = false;
+         else
+           {
+             tree binfo;
+             tree base_binfo;
+             int ix;
+
+             /* If the implicit destructor will be virtual, then we must
+                generate it now because (unfortunately) we do not
+                generate virtual tables lazily.  */
+             binfo = TYPE_BINFO (t);
+             for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
+               {
+                 tree base_type;
+                 tree dtor;
+
+                 base_type = BINFO_TYPE (base_binfo);
+                 dtor = CLASSTYPE_DESTRUCTORS (base_type);
+                 if (dtor && DECL_VIRTUAL_P (dtor))
+                   {
+                     lazy_p = false;
+                     break;
+                   }
+               }
+           }
 
-         if (DECL_VINDEX (default_fn))
-           virtual_dtor = default_fn;
+         /* If we can't get away with being lazy, generate the destructor
+            now.  */
+         if (!lazy_p)
+           lazily_declare_fn (sfk_destructor, t);
        }
     }
-  else
-    /* Any non-implicit destructor is non-trivial.  */
-    TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
 
   /* Default constructor.  */
-  if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor)
+  if (! TYPE_HAS_CONSTRUCTOR (t))
     {
       TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
       CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
@@ -2586,29 +2577,6 @@ add_implicitly_declared_members (tree t,
       TYPE_HAS_CONST_ASSIGN_REF (t) = !cant_have_const_assignment;
       CLASSTYPE_LAZY_ASSIGNMENT_OP (t) = 1;
     }
-  
-  /* Now, hook all of the new functions on to TYPE_METHODS,
-     and add them to the CLASSTYPE_METHOD_VEC.  */
-  for (f = &implicit_fns; *f; f = &TREE_CHAIN (*f))
-    {
-      add_method (t, *f);
-      maybe_add_class_template_decl_list (current_class_type, *f, /*friend_p=*/0);
-    }
-  if (abi_version_at_least (2))
-    /* G++ 3.2 put the implicit destructor at the *beginning* of the
-       list, which cause the destructor to be emitted in an incorrect
-       location in the vtable.  */
-    TYPE_METHODS (t) = chainon (TYPE_METHODS (t), implicit_fns);
-  else
-    {
-      if (warn_abi && virtual_dtor)
-       warning ("vtable layout for class `%T' may not be ABI-compliant "
-                "and may change in a future version of GCC due to implicit "
-                "virtual destructor",
-                t);
-      *f = TYPE_METHODS (t);
-      TYPE_METHODS (t) = implicit_fns;
-    }
 }
 
 /* Subroutine of finish_struct_1.  Recursively count the number of fields
@@ -2660,7 +2628,7 @@ check_bitfield_decl (tree field)
   if (DECL_INITIAL (field)
       && ! INTEGRAL_TYPE_P (TREE_TYPE (field)))
     {
-      cp_error_at ("bit-field `%#D' with non-integral type", field);
+      error ("bit-field %q+#D with non-integral type", field);
       w = error_mark_node;
     }
 
@@ -2673,31 +2641,27 @@ check_bitfield_decl (tree field)
       STRIP_NOPS (w);
 
       /* detect invalid field size.  */
-      if (TREE_CODE (w) == CONST_DECL)
-       w = DECL_INITIAL (w);
-      else
-       w = decl_constant_value (w);
+      w = integral_constant_value (w);
 
       if (TREE_CODE (w) != INTEGER_CST)
        {
-         cp_error_at ("bit-field `%D' width not an integer constant",
-                      field);
+         error ("bit-field %q+D width not an integer constant", field);
          w = error_mark_node;
        }
       else if (tree_int_cst_sgn (w) < 0)
        {
-         cp_error_at ("negative width in bit-field `%D'", field);
+         error ("negative width in bit-field %q+D", field);
          w = error_mark_node;
        }
       else if (integer_zerop (w) && DECL_NAME (field) != 0)
        {
-         cp_error_at ("zero width for bit-field `%D'", field);
+         error ("zero width for bit-field %q+D", field);
          w = error_mark_node;
        }
       else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0
               && TREE_CODE (type) != ENUMERAL_TYPE
               && TREE_CODE (type) != BOOLEAN_TYPE)
-       cp_warning_at ("width of `%D' exceeds its type", field);
+       warning (0, "width of %q+D exceeds its type", field);
       else if (TREE_CODE (type) == ENUMERAL_TYPE
               && (0 > compare_tree_int (w,
                                         min_precision (TYPE_MIN_VALUE (type),
@@ -2706,10 +2670,9 @@ check_bitfield_decl (tree field)
                                             min_precision
                                             (TYPE_MAX_VALUE (type),
                                              TYPE_UNSIGNED (type)))))
-       cp_warning_at ("`%D' is too small to hold all values of `%#T'",
-                      field, type);
+       warning (0, "%q+D is too small to hold all values of %q#T", field, type);
     }
-  
+
   /* Remove the bit-field width indicator so that the rest of the
      compiler does not treat that value as an initializer.  */
   DECL_INITIAL (field) = NULL_TREE;
@@ -2733,10 +2696,9 @@ check_bitfield_decl (tree field)
 
 static void
 check_field_decl (tree field,
-                  tree t,
-                  int* cant_have_const_ctor,
-                 int* cant_have_default_ctor,
-                  int* no_const_asn_ref,
+                 tree t,
+                 int* cant_have_const_ctor,
+                 int* no_const_asn_ref,
                  int* any_default_members)
 {
   tree type = strip_array_types (TREE_TYPE (field));
@@ -2754,8 +2716,7 @@ check_field_decl (tree field,
       for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
        if (TREE_CODE (fields) == FIELD_DECL && !DECL_C_BIT_FIELD (field))
          check_field_decl (fields, t, cant_have_const_ctor,
-                           cant_have_default_ctor, no_const_asn_ref,
-                           any_default_members);
+                           no_const_asn_ref, any_default_members);
     }
   /* Check members with class type for constructors, destructors,
      etc.  */
@@ -2764,23 +2725,22 @@ check_field_decl (tree field,
       /* Never let anything with uninheritable virtuals
         make it through without complaint.  */
       abstract_virtuals_error (field, type);
-                     
+
       if (TREE_CODE (t) == UNION_TYPE)
        {
          if (TYPE_NEEDS_CONSTRUCTING (type))
-           cp_error_at ("member `%#D' with constructor not allowed in union",
-                        field);
+           error ("member %q+#D with constructor not allowed in union",
+                  field);
          if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
-           cp_error_at ("member `%#D' with destructor not allowed in union",
-                        field);
+           error ("member %q+#D with destructor not allowed in union", field);
          if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
-           cp_error_at ("member `%#D' with copy assignment operator not allowed in union",
-                        field);
+           error ("member %q+#D with copy assignment operator not allowed in union",
+                  field);
        }
       else
        {
          TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
-         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) 
+         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
            |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
          TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
          TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
@@ -2791,17 +2751,13 @@ check_field_decl (tree field,
 
       if (!TYPE_HAS_CONST_ASSIGN_REF (type))
        *no_const_asn_ref = 1;
-
-      if (TYPE_HAS_CONSTRUCTOR (type)
-         && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
-       *cant_have_default_ctor = 1;
     }
   if (DECL_INITIAL (field) != NULL_TREE)
     {
       /* `build_class_init_list' does not recognize
         non-FIELD_DECLs.  */
       if (TREE_CODE (t) == UNION_TYPE && any_default_members != 0)
-       error ("multiple fields in union `%T' initialized", t);
+       error ("multiple fields in union %qT initialized", t);
       *any_default_members = 1;
     }
 }
@@ -2817,10 +2773,6 @@ check_field_decl (tree field,
      EMPTY_P
        The class is empty, i.e., contains no non-static data members.
 
-     CANT_HAVE_DEFAULT_CTOR_P
-       This class cannot have an implicitly generated default
-       constructor.
-
      CANT_HAVE_CONST_CTOR_P
        This class cannot have an implicitly generated copy constructor
        taking a const reference.
@@ -2837,7 +2789,6 @@ check_field_decl (tree field,
 
 static void
 check_field_decls (tree t, tree *access_decls,
-                  int *cant_have_default_ctor_p, 
                   int *cant_have_const_ctor_p,
                   int *no_const_asn_ref_p)
 {
@@ -2866,10 +2817,11 @@ check_field_decls (tree t, tree *access_decls,
          if (TYPE_PACKED (t))
            {
              if (!pod_type_p (TREE_TYPE (x)) && !TYPE_PACKED (TREE_TYPE (x)))
-               cp_warning_at
-                 ("ignoring packed attribute on unpacked non-POD field `%#D'",
+               warning
+                 (0,
+                  "ignoring packed attribute on unpacked non-POD field %q+#D",
                   x);
-             else
+             else if (TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
                DECL_PACKED (x) = 1;
            }
 
@@ -2888,7 +2840,7 @@ check_field_decls (tree t, tree *access_decls,
              /* If one of the data members contains an empty class,
                 so does T.  */
              element_type = strip_array_types (type);
-             if (CLASS_TYPE_P (element_type) 
+             if (CLASS_TYPE_P (element_type)
                  && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type))
                CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
            }
@@ -2927,40 +2879,40 @@ check_field_decls (tree t, tree *access_decls,
             reference type, the program is ill-formed.  */
          if (TREE_CODE (x) == VAR_DECL)
            {
-             cp_error_at ("`%D' may not be static because it is a member of a union", x);
+             error ("%q+D may not be static because it is a member of a union", x);
              continue;
            }
          if (TREE_CODE (type) == REFERENCE_TYPE)
            {
-             cp_error_at ("`%D' may not have reference type `%T' because it is a member of a union",
-                          x, type);
+             error ("%q+D may not have reference type %qT because"
+                    " it is a member of a union",
+                    x, type);
              continue;
            }
        }
 
       /* ``A local class cannot have static data members.'' ARM 9.4 */
       if (current_function_decl && TREE_STATIC (x))
-       cp_error_at ("field `%D' in local class cannot be static", x);
+       error ("field %q+D in local class cannot be static", x);
 
       /* Perform error checking that did not get done in
         grokdeclarator.  */
       if (TREE_CODE (type) == FUNCTION_TYPE)
        {
-         cp_error_at ("field `%D' invalidly declared function type",
-                      x);
+         error ("field %q+D invalidly declared function type", x);
          type = build_pointer_type (type);
          TREE_TYPE (x) = type;
        }
       else if (TREE_CODE (type) == METHOD_TYPE)
        {
-         cp_error_at ("field `%D' invalidly declared method type", x);
+         error ("field %q+D invalidly declared method type", x);
          type = build_pointer_type (type);
          TREE_TYPE (x) = type;
        }
 
       if (type == error_mark_node)
        continue;
-         
+
       if (TREE_CODE (x) == CONST_DECL || TREE_CODE (x) == VAR_DECL)
        continue;
 
@@ -2972,7 +2924,7 @@ check_field_decls (tree t, tree *access_decls,
       /* If this is of reference type, check if it needs an init.
         Also do a little ANSI jig if necessary.  */
       if (TREE_CODE (type) == REFERENCE_TYPE)
-       {
+       {
          CLASSTYPE_NON_POD_P (t) = 1;
          if (DECL_INITIAL (x) == NULL_TREE)
            SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
@@ -2981,12 +2933,11 @@ check_field_decls (tree t, tree *access_decls,
             aggregate, initialization by a brace-enclosed list) is the
             only way to initialize nonstatic const and reference
             members.  */
-         *cant_have_default_ctor_p = 1;
          TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
 
          if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
              && extra_warnings)
-            cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
+           warning (OPT_Wextra, "non-static reference %q+#D in class without a constructor", x);
        }
 
       type = strip_array_types (type);
@@ -3011,8 +2962,8 @@ check_field_decls (tree t, tree *access_decls,
        CLASSTYPE_HAS_MUTABLE (t) = 1;
 
       if (! pod_type_p (type))
-        /* DR 148 now allows pointers to members (which are POD themselves),
-           to be allowed in POD structs.  */
+       /* DR 148 now allows pointers to members (which are POD themselves),
+          to be allowed in POD structs.  */
        CLASSTYPE_NON_POD_P (t) = 1;
 
       if (! zero_init_p (type))
@@ -3029,12 +2980,11 @@ check_field_decls (tree t, tree *access_decls,
             aggregate, initialization by a brace-enclosed list) is the
             only way to initialize nonstatic const and reference
             members.  */
-         *cant_have_default_ctor_p = 1;
          TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
 
          if (! TYPE_HAS_CONSTRUCTOR (t) && CLASSTYPE_NON_AGGREGATE (t)
              && extra_warnings)
-            cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
+           warning (OPT_Wextra, "non-static const member %q+#D in class without a constructor", x);
        }
       /* A field that is pseudo-const makes the structure likewise.  */
       else if (CLASS_TYPE_P (type))
@@ -3049,7 +2999,7 @@ check_field_decls (tree t, tree *access_decls,
         different name from the class iff the class has a
         user-defined constructor.  */
       if (constructor_name_p (DECL_NAME (x), t) && TYPE_HAS_CONSTRUCTOR (t))
-       cp_pedwarn_at ("field `%#D' with same name as class", x);
+       pedwarn ("field %q+#D with same name as class", x);
 
       /* We set DECL_C_BIT_FIELD in grokbitfield.
         If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
@@ -3058,7 +3008,6 @@ check_field_decls (tree t, tree *access_decls,
       else
        check_field_decl (x, t,
                          cant_have_const_ctor_p,
-                         cant_have_default_ctor_p, 
                          no_const_asn_ref_p,
                          &any_default_members);
     }
@@ -3075,24 +3024,26 @@ check_field_decls (tree t, tree *access_decls,
      -- Warn only if there is a non-trivial destructor. We assume that the
        user at least implemented the cleanup correctly, and a destructor
        is needed to free dynamic memory.
-       
-     This seems enough for pratical purposes.  */
+
+     This seems enough for practical purposes.  */
     if (warn_ecpp
        && has_pointers
        && TYPE_HAS_CONSTRUCTOR (t)
-       && TYPE_HAS_DESTRUCTOR (t)
+       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
        && !(TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
     {
-      warning ("`%#T' has pointer data members", t);
-      
+      warning (OPT_Weffc__, "%q#T has pointer data members", t);
+
       if (! TYPE_HAS_INIT_REF (t))
        {
-         warning ("  but does not override `%T(const %T&)'", t, t);
-         if (! TYPE_HAS_ASSIGN_REF (t))
-           warning ("  or `operator=(const %T&)'", t);
+         warning (OPT_Weffc__,
+                   "  but does not override %<%T(const %T&)%>", t, t);
+         if (!TYPE_HAS_ASSIGN_REF (t))
+           warning (OPT_Weffc__, "  or %<operator=(const %T&)%>", t);
        }
       else if (! TYPE_HAS_ASSIGN_REF (t))
-       warning ("  but does not override `operator=(const %T&)'", t);
+       warning (OPT_Weffc__,
+                 "  but does not override %<operator=(const %T&)%>", t);
     }
 
 
@@ -3118,10 +3069,10 @@ record_subobject_offset (tree type, tree offset, splay_tree offsets)
   /* Record the location of this empty object in OFFSETS.  */
   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
   if (!n)
-    n = splay_tree_insert (offsets, 
+    n = splay_tree_insert (offsets,
                           (splay_tree_key) offset,
                           (splay_tree_value) NULL_TREE);
-  n->value = ((splay_tree_value) 
+  n->value = ((splay_tree_value)
              tree_cons (NULL_TREE,
                         type,
                         (tree) n->value));
@@ -3165,12 +3116,12 @@ check_subobject_offset (tree type, tree offset, splay_tree offsets)
    is returned.  Otherwise, returns zero.  */
 
 static int
-walk_subobject_offsets (tree type, 
-                        subobject_offset_fn f, 
-                        tree offset, 
-                        splay_tree offsets, 
-                        tree max_offset, 
-                        int vbases_p)
+walk_subobject_offsets (tree type,
+                       subobject_offset_fn f,
+                       tree offset,
+                       splay_tree offsets,
+                       tree max_offset,
+                       int vbases_p)
 {
   int r = 0;
   tree type_binfo = NULL_TREE;
@@ -3180,7 +3131,10 @@ walk_subobject_offsets (tree type,
   if (max_offset && INT_CST_LT (max_offset, offset))
     return 0;
 
-  if (!TYPE_P (type)) 
+  if (type == error_mark_node)
+    return 0;
+  
+  if (!TYPE_P (type))
     {
       if (abi_version_at_least (2))
        type_binfo = type;
@@ -3209,12 +3163,12 @@ walk_subobject_offsets (tree type,
        {
          tree binfo_offset;
 
-         if (abi_version_at_least (2) 
+         if (abi_version_at_least (2)
              && BINFO_VIRTUAL_P (binfo))
            continue;
 
-         if (!vbases_p 
-             && BINFO_VIRTUAL_P (binfo) 
+         if (!vbases_p
+             && BINFO_VIRTUAL_P (binfo)
              && !BINFO_PRIMARY_P (binfo))
            continue;
 
@@ -3229,7 +3183,7 @@ walk_subobject_offsets (tree type,
                 class yet, but the offsets for direct non-virtual
                 bases can be calculated by going back to the TYPE.  */
              orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
-             binfo_offset = size_binop (PLUS_EXPR,           
+             binfo_offset = size_binop (PLUS_EXPR,
                                         offset,
                                         BINFO_OFFSET (orig_binfo));
            }
@@ -3239,7 +3193,7 @@ walk_subobject_offsets (tree type,
                                      binfo_offset,
                                      offsets,
                                      max_offset,
-                                     (abi_version_at_least (2) 
+                                     (abi_version_at_least (2)
                                       ? /*vbases_p=*/0 : vbases_p));
          if (r)
            return r;
@@ -3248,7 +3202,7 @@ walk_subobject_offsets (tree type,
       if (abi_version_at_least (2) && CLASSTYPE_VBASECLASSES (type))
        {
          unsigned ix;
-         VEC (tree) *vbases;
+         VEC(tree,gc) *vbases;
 
          /* Iterate through the virtual base classes of TYPE.  In G++
             3.2, we included virtual bases in the direct base class
@@ -3276,12 +3230,12 @@ walk_subobject_offsets (tree type,
                 virtual.  (If it is non-virtual, then it was walked
                 above.)  */
              tree vbase = get_primary_binfo (type_binfo);
-             
+
              if (vbase && BINFO_VIRTUAL_P (vbase)
                  && BINFO_PRIMARY_P (vbase)
                  && BINFO_INHERITANCE_CHAIN (vbase) == type_binfo)
                {
-                 r = (walk_subobject_offsets 
+                 r = (walk_subobject_offsets
                       (vbase, f, offset,
                        offsets, max_offset, /*vbases_p=*/0));
                  if (r)
@@ -3328,7 +3282,7 @@ walk_subobject_offsets (tree type,
       /* Step through each of the elements in the array.  */
       for (index = size_zero_node;
           /* G++ 3.2 had an off-by-one error here.  */
-          (abi_version_at_least (2) 
+          (abi_version_at_least (2)
            ? !INT_CST_LT (TYPE_MAX_VALUE (domain), index)
            : INT_CST_LT (index, TYPE_MAX_VALUE (domain)));
           index = size_binop (PLUS_EXPR, index, size_one_node))
@@ -3341,7 +3295,7 @@ walk_subobject_offsets (tree type,
                                      /*vbases_p=*/1);
          if (r)
            return r;
-         offset = size_binop (PLUS_EXPR, offset, 
+         offset = size_binop (PLUS_EXPR, offset,
                               TYPE_SIZE_UNIT (TREE_TYPE (type)));
          /* If this new OFFSET is bigger than the MAX_OFFSET, then
             there's no point in iterating through the remaining
@@ -3354,18 +3308,38 @@ walk_subobject_offsets (tree type,
   return 0;
 }
 
-/* Record all of the empty subobjects of TYPE (located at OFFSET) in
-   OFFSETS.  If VBASES_P is nonzero, virtual bases of TYPE are
-   examined.  */
+/* Record all of the empty subobjects of TYPE (either a type or a
+   binfo).  If IS_DATA_MEMBER is true, then a non-static data member
+   is being placed at OFFSET; otherwise, it is a base class that is
+   being placed at OFFSET.  */
 
 static void
-record_subobject_offsets (tree type, 
-                          tree offset, 
-                          splay_tree offsets, 
-                          int vbases_p)
-{
+record_subobject_offsets (tree type,
+                         tree offset,
+                         splay_tree offsets,
+                         bool is_data_member)
+{
+  tree max_offset;
+  /* If recording subobjects for a non-static data member or a
+     non-empty base class , we do not need to record offsets beyond
+     the size of the biggest empty class.  Additional data members
+     will go at the end of the class.  Additional base classes will go
+     either at offset zero (if empty, in which case they cannot
+     overlap with offsets past the size of the biggest empty class) or
+     at the end of the class.
+
+     However, if we are placing an empty base class, then we must record
+     all offsets, as either the empty class is at offset zero (where
+     other empty classes might later be placed) or at the end of the
+     class (where other objects might then be placed, so other empty
+     subobjects might later overlap).  */
+  if (is_data_member 
+      || !is_empty_class (BINFO_TYPE (type)))
+    max_offset = sizeof_biggest_empty_class;
+  else
+    max_offset = NULL_TREE;
   walk_subobject_offsets (type, record_subobject_offset, offset,
-                         offsets, /*max_offset=*/NULL_TREE, vbases_p);
+                         offsets, max_offset, is_data_member);
 }
 
 /* Returns nonzero if any of the empty subobjects of TYPE (located at
@@ -3374,9 +3348,9 @@ record_subobject_offsets (tree type,
 
 static int
 layout_conflict_p (tree type,
-                   tree offset, 
-                   splay_tree offsets, 
-                   int vbases_p)
+                  tree offset,
+                  splay_tree offsets,
+                  int vbases_p)
 {
   splay_tree_node max_node;
 
@@ -3400,15 +3374,15 @@ layout_conflict_p (tree type,
    the position of the DECL.  */
 
 static void
-layout_nonempty_base_or_field (record_layout_info rli, 
-                              tree decl, 
-                              tree binfo, 
+layout_nonempty_base_or_field (record_layout_info rli,
+                              tree decl,
+                              tree binfo,
                               splay_tree offsets)
 {
   tree offset = NULL_TREE;
   bool field_p;
   tree type;
-  
+
   if (binfo)
     {
       /* For the purposes of determining layout conflicts, we want to
@@ -3438,11 +3412,11 @@ layout_nonempty_base_or_field (record_layout_info rli,
       /* We have to check to see whether or not there is already
         something of the same type at the offset we're about to use.
         For example, consider:
-        
+
           struct S {};
           struct T : public S { int i; };
           struct U : public S, public T {};
-        
+
         Here, we put S at offset zero in U.  Then, we can't put T at
         offset zero -- its S component would be at the same address
         as the S we already allocated.  So, we have to skip ahead.
@@ -3458,7 +3432,7 @@ layout_nonempty_base_or_field (record_layout_info rli,
         virtual base.  */
       if (!abi_version_at_least (2) && binfo && BINFO_VIRTUAL_P (binfo))
        break;
-      if (layout_conflict_p (field_p ? type : binfo, offset, 
+      if (layout_conflict_p (field_p ? type : binfo, offset,
                             offsets, field_p))
        {
          /* Strip off the size allocated to this field.  That puts us
@@ -3468,8 +3442,8 @@ layout_nonempty_base_or_field (record_layout_info rli,
 
          /* Bump up by the alignment required for the type.  */
          rli->bitpos
-           = size_binop (PLUS_EXPR, rli->bitpos, 
-                         bitsize_int (binfo 
+           = size_binop (PLUS_EXPR, rli->bitpos,
+                         bitsize_int (binfo
                                       ? CLASSTYPE_ALIGN (type)
                                       : TYPE_ALIGN (type)));
          normalize_rli (rli);
@@ -3486,9 +3460,9 @@ layout_nonempty_base_or_field (record_layout_info rli,
        this point because their BINFO_OFFSET is copied from another
        hierarchy.  Therefore, we may not need to add the entire
        OFFSET.  */
-    propagate_binfo_offsets (binfo, 
+    propagate_binfo_offsets (binfo,
                             size_diffop (convert (ssizetype, offset),
-                                         convert (ssizetype, 
+                                         convert (ssizetype,
                                                   BINFO_OFFSET (binfo))));
 }
 
@@ -3524,27 +3498,28 @@ layout_empty_base (tree binfo, tree eoc, splay_tree offsets)
       if (abi_version_at_least (2))
        propagate_binfo_offsets
          (binfo, size_diffop (size_zero_node, BINFO_OFFSET (binfo)));
-      else if (warn_abi)
-       warning ("offset of empty base `%T' may not be ABI-compliant and may"
+      else
+       warning (OPT_Wabi,
+                 "offset of empty base %qT may not be ABI-compliant and may"
                 "change in a future version of GCC",
                 BINFO_TYPE (binfo));
     }
-  
+
   /* This is an empty base class.  We first try to put it at offset
      zero.  */
   if (layout_conflict_p (binfo,
                         BINFO_OFFSET (binfo),
-                        offsets, 
+                        offsets,
                         /*vbases_p=*/0))
     {
       /* That didn't work.  Now, we move forward from the next
         available spot in the class.  */
       atend = true;
       propagate_binfo_offsets (binfo, convert (ssizetype, eoc));
-      while (1) 
+      while (1)
        {
          if (!layout_conflict_p (binfo,
-                                 BINFO_OFFSET (binfo), 
+                                 BINFO_OFFSET (binfo),
                                  offsets,
                                  /*vbases_p=*/0))
            /* We finally found a spot where there's no overlap.  */
@@ -3557,12 +3532,12 @@ layout_empty_base (tree binfo, tree eoc, splay_tree offsets)
   return atend;
 }
 
-/* Layout the the base given by BINFO in the class indicated by RLI.
+/* Layout the base given by BINFO in the class indicated by RLI.
    *BASE_ALIGN is a running maximum of the alignments of
    any base class.  OFFSETS gives the location of empty base
    subobjects.  T is the most derived type.  Return nonzero if the new
    object cannot be nearly-empty.  A new FIELD_DECL is inserted at
-   *NEXT_FIELD, unless BINFO is for an empty base class.  
+   *NEXT_FIELD, unless BINFO is for an empty base class.
 
    Returns the location at which the next field should be inserted.  */
 
@@ -3577,7 +3552,7 @@ build_base_field (record_layout_info rli, tree binfo,
     /* This error is now reported in xref_tag, thus giving better
        location information.  */
     return next_field;
-  
+
   /* Place the base class.  */
   if (!is_empty_class (basetype))
     {
@@ -3586,16 +3561,17 @@ build_base_field (record_layout_info rli, tree binfo,
       /* The containing class is non-empty because it has a non-empty
         base class.  */
       CLASSTYPE_EMPTY_P (t) = 0;
-      
+
       /* Create the FIELD_DECL.  */
       decl = build_decl (FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
       DECL_ARTIFICIAL (decl) = 1;
+      DECL_IGNORED_P (decl) = 1;
       DECL_FIELD_CONTEXT (decl) = t;
       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
       DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
       DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
-      DECL_IGNORED_P (decl) = 1;
+      DECL_MODE (decl) = TYPE_MODE (basetype);
       DECL_FIELD_IS_BASE (decl) = 1;
 
       /* Try to place the field.  It may take more than one try if we
@@ -3623,10 +3599,10 @@ build_base_field (record_layout_info rli, tree binfo,
        {
          if (atend)
            CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
-         /* The check above (used in G++ 3.2) is insufficient  because
+         /* The check above (used in G++ 3.2) is insufficient because
             an empty class placed at offset zero might itself have an
             empty base at a nonzero offset.  */
-         else if (walk_subobject_offsets (basetype, 
+         else if (walk_subobject_offsets (basetype,
                                           empty_base_at_nonzero_offset_p,
                                           size_zero_node,
                                           /*offsets=*/NULL,
@@ -3635,12 +3611,13 @@ build_base_field (record_layout_info rli, tree binfo,
            {
              if (abi_version_at_least (2))
                CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
-             else if (warn_abi)
-               warning ("class `%T' will be considered nearly empty in a "
+             else
+               warning (OPT_Wabi,
+                         "class %qT will be considered nearly empty in a "
                         "future version of GCC", t);
            }
        }
-       
+
       /* We do not create a FIELD_DECL for empty base classes because
         it might overlap some other field.  We want to be able to
         create CONSTRUCTORs for the class by iterating over the
@@ -3656,8 +3633,8 @@ build_base_field (record_layout_info rli, tree binfo,
   /* Record the offsets of BINFO and its base subobjects.  */
   record_subobject_offsets (binfo,
                            BINFO_OFFSET (binfo),
-                           offsets, 
-                           /*vbases_p=*/0);
+                           offsets,
+                           /*is_data_member=*/false);
 
   return next_field;
 }
@@ -3718,16 +3695,18 @@ check_methods (tree t)
     {
       check_for_override (x, t);
       if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x))
-       cp_error_at ("initializer specified for non-virtual method `%D'", x);
+       error ("initializer specified for non-virtual method %q+D", x);
       /* The name of the field is the original field name
         Save this in auxiliary field for later overloading.  */
       if (DECL_VINDEX (x))
        {
          TYPE_POLYMORPHIC_P (t) = 1;
          if (DECL_PURE_VIRTUAL_P (x))
-           CLASSTYPE_PURE_VIRTUALS (t)
-             = tree_cons (NULL_TREE, x, CLASSTYPE_PURE_VIRTUALS (t));
+           VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
        }
+      /* All user-declared destructors are non-trivial.  */
+      if (DECL_DESTRUCTOR_P (x))
+       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 1;
     }
 }
 
@@ -3784,14 +3763,14 @@ build_clone (tree fn, tree name)
        parmtypes = TREE_CHAIN (parmtypes);
        /* If this is subobject constructor or destructor, add the vtt
         parameter.  */
-      TREE_TYPE (clone) 
+      TREE_TYPE (clone)
        = build_method_type_directly (basetype,
                                      TREE_TYPE (TREE_TYPE (clone)),
                                      parmtypes);
       if (exceptions)
        TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone),
                                                     exceptions);
-      TREE_TYPE (clone) 
+      TREE_TYPE (clone)
        = cp_build_type_attribute_variant (TREE_TYPE (clone),
                                           TYPE_ATTRIBUTES (TREE_TYPE (fn)));
     }
@@ -3831,7 +3810,7 @@ build_clone (tree fn, tree name)
   /* Create the RTL for this function.  */
   SET_DECL_RTL (clone, NULL_RTX);
   rest_of_decl_compilation (clone, /*top_level=*/1, at_eof);
-  
+
   /* Make it easy to find the CLONE given the FN.  */
   TREE_CHAIN (clone) = TREE_CHAIN (fn);
   TREE_CHAIN (fn) = clone;
@@ -3841,12 +3820,14 @@ build_clone (tree fn, tree name)
     {
       tree result;
 
-      DECL_TEMPLATE_RESULT (clone) 
+      DECL_TEMPLATE_RESULT (clone)
        = build_clone (DECL_TEMPLATE_RESULT (clone), name);
       result = DECL_TEMPLATE_RESULT (clone);
       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
       DECL_TI_TEMPLATE (result) = clone;
     }
+  else if (pch_file)
+    note_decl_for_pch (clone);
 
   return clone;
 }
@@ -3871,10 +3852,10 @@ clone_function_decl (tree fn, int update_method_vec_p)
         and a not-in-charge version.  */
       clone = build_clone (fn, complete_ctor_identifier);
       if (update_method_vec_p)
-       add_method (DECL_CONTEXT (clone), clone);
+       add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
       clone = build_clone (fn, base_ctor_identifier);
       if (update_method_vec_p)
-       add_method (DECL_CONTEXT (clone), clone);
+       add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
     }
   else
     {
@@ -3885,22 +3866,22 @@ clone_function_decl (tree fn, int update_method_vec_p)
         version.  We clone the deleting version first because that
         means it will go second on the TYPE_METHODS list -- and that
         corresponds to the correct layout order in the virtual
-        function table.  
+        function table.
 
-         For a non-virtual destructor, we do not build a deleting
+        For a non-virtual destructor, we do not build a deleting
         destructor.  */
       if (DECL_VIRTUAL_P (fn))
        {
          clone = build_clone (fn, deleting_dtor_identifier);
          if (update_method_vec_p)
-           add_method (DECL_CONTEXT (clone), clone);
+           add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
        }
       clone = build_clone (fn, complete_dtor_identifier);
       if (update_method_vec_p)
-       add_method (DECL_CONTEXT (clone), clone);
+       add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
       clone = build_clone (fn, base_dtor_identifier);
       if (update_method_vec_p)
-       add_method (DECL_CONTEXT (clone), clone);
+       add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
     }
 
   /* Note that this is an abstract function that is never emitted.  */
@@ -3918,7 +3899,7 @@ void
 adjust_clone_args (tree decl)
 {
   tree clone;
-  
+
   for (clone = TREE_CHAIN (decl); clone && DECL_CLONED_FUNCTION (clone);
        clone = TREE_CHAIN (clone))
     {
@@ -3927,7 +3908,7 @@ adjust_clone_args (tree decl)
       tree decl_parms, clone_parms;
 
       clone_parms = orig_clone_parms;
-      
+
       /* Skip the 'this' parameter.  */
       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
@@ -3936,18 +3917,18 @@ adjust_clone_args (tree decl)
        orig_decl_parms = TREE_CHAIN (orig_decl_parms);
       if (DECL_HAS_VTT_PARM_P (decl))
        orig_decl_parms = TREE_CHAIN (orig_decl_parms);
-      
+
       clone_parms = orig_clone_parms;
       if (DECL_HAS_VTT_PARM_P (clone))
        clone_parms = TREE_CHAIN (clone_parms);
-      
+
       for (decl_parms = orig_decl_parms; decl_parms;
           decl_parms = TREE_CHAIN (decl_parms),
             clone_parms = TREE_CHAIN (clone_parms))
        {
          gcc_assert (same_type_p (TREE_TYPE (decl_parms),
                                   TREE_TYPE (clone_parms)));
-         
+
          if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
            {
              /* A default parameter has been added. Adjust the
@@ -3971,7 +3952,7 @@ adjust_clone_args (tree decl)
              if (exceptions)
                type = build_exception_variant (type, exceptions);
              TREE_TYPE (clone) = type;
-             
+
              clone_parms = NULL_TREE;
              break;
            }
@@ -4006,11 +3987,11 @@ remove_zero_width_bit_fields (tree t)
 {
   tree *fieldsp;
 
-  fieldsp = &TYPE_FIELDS (t); 
+  fieldsp = &TYPE_FIELDS (t);
   while (*fieldsp)
     {
       if (TREE_CODE (*fieldsp) == FIELD_DECL
-         && DECL_C_BIT_FIELD (*fieldsp) 
+         && DECL_C_BIT_FIELD (*fieldsp)
          && DECL_INITIAL (*fieldsp))
        *fieldsp = TREE_CHAIN (*fieldsp);
       else
@@ -4039,7 +4020,7 @@ type_requires_array_cookie (tree type)
      argument is of type `size_t', then we have to pass the size of
      the array to the deallocation function, so we will need to store
      a cookie.  */
-  fns = lookup_fnfields (TYPE_BINFO (type), 
+  fns = lookup_fnfields (TYPE_BINFO (type),
                         ansi_opname (VEC_DELETE_EXPR),
                         /*protect=*/0);
   /* If there are no `operator []' members, or the lookup is
@@ -4079,36 +4060,34 @@ type_requires_array_cookie (tree type)
 static void
 check_bases_and_members (tree t)
 {
-  /* Nonzero if we are not allowed to generate a default constructor
-     for this case.  */
-  int cant_have_default_ctor;
   /* Nonzero if the implicitly generated copy constructor should take
      a non-const reference argument.  */
   int cant_have_const_ctor;
-  /* Nonzero if the the implicitly generated assignment operator
+  /* Nonzero if the implicitly generated assignment operator
      should take a non-const reference argument.  */
   int no_const_asn_ref;
   tree access_decls;
 
   /* By default, we use const reference arguments and generate default
      constructors.  */
-  cant_have_default_ctor = 0;
   cant_have_const_ctor = 0;
   no_const_asn_ref = 0;
 
   /* Check all the base-classes.  */
-  check_bases (t, &cant_have_default_ctor, &cant_have_const_ctor,
+  check_bases (t, &cant_have_const_ctor,
               &no_const_asn_ref);
 
-  /* Check all the data member declarations.  */
+  /* Check all the method declarations.  */
+  check_methods (t);
+
+  /* Check all the data member declarations.  We cannot call
+     check_field_decls until we have called check_bases check_methods,
+     as check_field_decls depends on TYPE_HAS_NONTRIVIAL_DESTRUCTOR
+     being set appropriately.  */
   check_field_decls (t, &access_decls,
-                    &cant_have_default_ctor,
                     &cant_have_const_ctor,
                     &no_const_asn_ref);
 
-  /* Check all the method declarations.  */
-  check_methods (t);
-
   /* A nearly-empty class has to be vptr-containing; a nearly empty
      class contains just a vptr.  */
   if (!TYPE_CONTAINS_VPTR_P (t))
@@ -4117,23 +4096,20 @@ check_bases_and_members (tree t)
   /* Do some bookkeeping that will guide the generation of implicitly
      declared member functions.  */
   TYPE_HAS_COMPLEX_INIT_REF (t)
-    |= (TYPE_HAS_INIT_REF (t) 
-       || TYPE_USES_VIRTUAL_BASECLASSES (t)
-       || TYPE_POLYMORPHIC_P (t));
+    |= (TYPE_HAS_INIT_REF (t) || TYPE_CONTAINS_VPTR_P (t));
   TYPE_NEEDS_CONSTRUCTING (t)
-    |= (TYPE_HAS_CONSTRUCTOR (t) 
-       || TYPE_USES_VIRTUAL_BASECLASSES (t)
-       || TYPE_POLYMORPHIC_P (t));
-  CLASSTYPE_NON_AGGREGATE (t) |= (TYPE_HAS_CONSTRUCTOR (t)
-                                 || TYPE_POLYMORPHIC_P (t));
+    |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_CONTAINS_VPTR_P (t));
+  CLASSTYPE_NON_AGGREGATE (t)
+    |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_POLYMORPHIC_P (t));
   CLASSTYPE_NON_POD_P (t)
-    |= (CLASSTYPE_NON_AGGREGATE (t) || TYPE_HAS_DESTRUCTOR (t) 
+    |= (CLASSTYPE_NON_AGGREGATE (t)
+       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
        || TYPE_HAS_ASSIGN_REF (t));
   TYPE_HAS_COMPLEX_ASSIGN_REF (t)
     |= TYPE_HAS_ASSIGN_REF (t) || TYPE_CONTAINS_VPTR_P (t);
 
-  /* Synthesize any needed methods.   */
-  add_implicitly_declared_members (t, cant_have_default_ctor,
+  /* Synthesize any needed methods.  */
+  add_implicitly_declared_members (t,
                                   cant_have_const_ctor,
                                   no_const_asn_ref);
 
@@ -4172,14 +4148,15 @@ create_vtable_ptr (tree t, tree* virtuals_p)
        && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
       {
        tree new_virtual = make_node (TREE_LIST);
-       
+
        BV_FN (new_virtual) = fn;
        BV_DELTA (new_virtual) = integer_zero_node;
+       BV_VCALL_INDEX (new_virtual) = NULL_TREE;
 
        TREE_CHAIN (new_virtual) = *virtuals_p;
        *virtuals_p = new_virtual;
       }
-  
+
   /* If we couldn't find an appropriate base class, create a new field
      here.  Even if there weren't any new virtual functions, we might need a
      new virtual function table if we're supposed to include vptrs in
@@ -4198,9 +4175,9 @@ create_vtable_ptr (tree t, tree* virtuals_p)
         the derived class vtable pointer, since they have different
         types.  Thus, in a derived class destructor, where the base
         class constructor was inlined, we could generate bad code for
-        setting up the vtable pointer.  
+        setting up the vtable pointer.
 
-         Therefore, we use one type for all vtable pointers.  We still
+        Therefore, we use one type for all vtable pointers.  We still
         use a type-correct type; it's just doesn't indicate the array
         bounds.  That's better than using `void*' or some such; it's
         cleaner, and it let's the alias analysis code know that these
@@ -4208,24 +4185,16 @@ create_vtable_ptr (tree t, tree* virtuals_p)
       tree field;
 
       field = build_decl (FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
-      SET_DECL_ASSEMBLER_NAME (field, get_identifier (VFIELD_BASE));
       DECL_VIRTUAL_P (field) = 1;
       DECL_ARTIFICIAL (field) = 1;
       DECL_FIELD_CONTEXT (field) = t;
       DECL_FCONTEXT (field) = t;
-      
+
       TYPE_VFIELD (t) = field;
-      
+
       /* This class is non-empty.  */
       CLASSTYPE_EMPTY_P (t) = 0;
 
-      if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
-       /* If there were any baseclasses, they can't possibly be at
-          offset zero any more, because that's where the vtable
-          pointer is.  So, converting to a base class is going to
-          take work.  */
-       TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (t) = 1;
-
       return field;
     }
 
@@ -4256,6 +4225,8 @@ static void
 fixup_inline_methods (tree type)
 {
   tree method = TYPE_METHODS (type);
+  VEC(tree,gc) *friends;
+  unsigned ix;
 
   if (method && TREE_CODE (method) == TREE_VEC)
     {
@@ -4272,11 +4243,10 @@ fixup_inline_methods (tree type)
     fixup_pending_inline (method);
 
   /* Do friends.  */
-  for (method = CLASSTYPE_INLINE_FRIENDS (type); 
-       method; 
-       method = TREE_CHAIN (method))
-    fixup_pending_inline (TREE_VALUE (method));
-  CLASSTYPE_INLINE_FRIENDS (type) = NULL_TREE;
+  for (friends = CLASSTYPE_INLINE_FRIENDS (type), ix = 0;
+       VEC_iterate (tree, friends, ix, method); ix++)
+    fixup_pending_inline (method);
+  CLASSTYPE_INLINE_FRIENDS (type) = NULL;
 }
 
 /* Add OFFSET to all base types of BINFO which is a base in the
@@ -4293,7 +4263,7 @@ propagate_binfo_offsets (tree binfo, tree offset)
 
   /* Update BINFO's offset.  */
   BINFO_OFFSET (binfo)
-    = convert (sizetype, 
+    = convert (sizetype,
               size_binop (PLUS_EXPR,
                           convert (ssizetype, BINFO_OFFSET (binfo)),
                           offset));
@@ -4303,7 +4273,7 @@ propagate_binfo_offsets (tree binfo, tree offset)
 
   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
     propagate_binfo_offsets (primary_binfo, offset);
-  
+
   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
      downwards.  */
   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
@@ -4381,13 +4351,15 @@ layout_virtual_bases (record_layout_info rli, splay_tree offsets)
             the results which is not particularly tractable.  */
          if (warn_abi
              && first_vbase
-             && (tree_int_cst_lt 
+             && (tree_int_cst_lt
                  (size_binop (CEIL_DIV_EXPR,
                               round_up (CLASSTYPE_SIZE (t),
                                         CLASSTYPE_ALIGN (basetype)),
                               bitsize_unit_node),
                   BINFO_OFFSET (vbase))))
-           warning ("offset of virtual base `%T' is not ABI-compliant and may change in a future version of GCC",
+           warning (OPT_Wabi,
+                     "offset of virtual base %qT is not ABI-compliant and "
+                    "may change in a future version of GCC",
                     basetype);
 
          first_vbase = false;
@@ -4422,7 +4394,7 @@ static tree
 end_of_class (tree t, int include_virtuals_p)
 {
   tree result = size_zero_node;
-  VEC (tree) *vbases;
+  VEC(tree,gc) *vbases;
   tree binfo;
   tree base_binfo;
   tree offset;
@@ -4469,19 +4441,23 @@ static void
 warn_about_ambiguous_bases (tree t)
 {
   int i;
-  VEC (tree) *vbases;
+  VEC(tree,gc) *vbases;
   tree basetype;
   tree binfo;
   tree base_binfo;
 
+  /* If there are no repeated bases, nothing can be ambiguous.  */
+  if (!CLASSTYPE_REPEATED_BASE_P (t))
+    return;
+
   /* Check direct bases.  */
   for (binfo = TYPE_BINFO (t), i = 0;
        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
     {
       basetype = BINFO_TYPE (base_binfo);
 
-      if (!lookup_base (t, basetype, ba_ignore | ba_quiet, NULL))
-       warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
+      if (!lookup_base (t, basetype, ba_unique | ba_quiet, NULL))
+       warning (0, "direct base %qT inaccessible in %qT due to ambiguity",
                 basetype, t);
     }
 
@@ -4491,9 +4467,9 @@ warn_about_ambiguous_bases (tree t)
         VEC_iterate (tree, vbases, i, binfo); i++)
       {
        basetype = BINFO_TYPE (binfo);
-       
-       if (!lookup_base (t, basetype, ba_ignore | ba_quiet, NULL))
-         warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
+
+       if (!lookup_base (t, basetype, ba_unique | ba_quiet, NULL))
+         warning (OPT_Wextra, "virtual base %qT inaccessible in %qT due to ambiguity",
                   basetype, t);
       }
 }
@@ -4520,7 +4496,7 @@ include_empty_classes (record_layout_info rli)
      because we are willing to overlay multiple bases at the same
      offset.  However, now we need to make sure that RLI is big enough
      to reflect the entire class.  */
-  eoc = end_of_class (rli->t, 
+  eoc = end_of_class (rli->t,
                      CLASSTYPE_AS_BASE (rli->t) != NULL_TREE);
   rli_size = rli_size_unit_so_far (rli);
   if (TREE_CODE (rli_size) == INTEGER_CST
@@ -4537,8 +4513,8 @@ include_empty_classes (record_layout_info rli)
        /* The size should have been rounded to a whole byte.  */
        gcc_assert (tree_int_cst_equal
                    (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
-      rli->bitpos 
-       = size_binop (PLUS_EXPR, 
+      rli->bitpos
+       = size_binop (PLUS_EXPR,
                      rli->bitpos,
                      size_binop (MULT_EXPR,
                                  convert (bitsizetype,
@@ -4594,10 +4570,10 @@ layout_class_type (tree t, tree *virtuals_p)
     next_field = &TYPE_FIELDS (t);
 
   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
-  empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts, 
+  empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
                                       NULL, NULL);
   build_base_fields (rli, empty_base_offsets, next_field);
-  
+
   /* Layout the non-static data members.  */
   for (field = non_static_data_members; field; field = TREE_CHAIN (field))
     {
@@ -4610,22 +4586,28 @@ layout_class_type (tree t, tree *virtuals_p)
        {
          place_field (rli, field);
          /* If the static data member has incomplete type, keep track
-            of it so that it can be completed later.  (The handling 
+            of it so that it can be completed later.  (The handling
             of pending statics in finish_record_layout is
             insufficient; consider:
 
               struct S1;
               struct S2 { static S1 s1; };
-              
-             At this point, finish_record_layout will be called, but
+
+            At this point, finish_record_layout will be called, but
             S1 is still incomplete.)  */
          if (TREE_CODE (field) == VAR_DECL)
-           maybe_register_incomplete_var (field);
+           {
+             maybe_register_incomplete_var (field);
+             /* The visibility of static data members is determined
+                at their point of declaration, not their point of
+                definition.  */
+             determine_visibility (field);
+           }
          continue;
        }
 
       type = TREE_TYPE (field);
-      
+
       padding = NULL_TREE;
 
       /* If this field is a bit-field whose width is greater than its
@@ -4642,7 +4624,7 @@ layout_class_type (tree t, tree *virtuals_p)
             of the field.  Then, we are supposed to use the left over
             bits as additional padding.  */
          for (itk = itk_char; itk != itk_none; ++itk)
-           if (INT_CST_LT (DECL_SIZE (field), 
+           if (INT_CST_LT (DECL_SIZE (field),
                            TYPE_SIZE (integer_types[itk])))
              break;
 
@@ -4663,10 +4645,10 @@ layout_class_type (tree t, tree *virtuals_p)
                padding = DECL_SIZE (field);
              else
                {
-                 if (warn_abi && TREE_CODE (t) == UNION_TYPE)
-                   warning ("size assigned to `%T' may not be "
+                 if (TREE_CODE (t) == UNION_TYPE)
+                   warning (OPT_Wabi, "size assigned to %qT may not be "
                             "ABI-compliant and may change in a future "
-                            "version of GCC", 
+                            "version of GCC",
                             t);
                  padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
                                        TYPE_SIZE (integer_type));
@@ -4703,7 +4685,8 @@ layout_class_type (tree t, tree *virtuals_p)
                   && DECL_MODE (field) != TYPE_MODE (type))
            /* Versions of G++ before G++ 3.4 did not reset the
               DECL_MODE.  */
-           warning ("the offset of `%D' may not be ABI-compliant and may "
+           warning (OPT_Wabi,
+                     "the offset of %qD may not be ABI-compliant and may "
                     "change in a future version of GCC", field);
        }
       else
@@ -4712,33 +4695,37 @@ layout_class_type (tree t, tree *virtuals_p)
 
       /* Remember the location of any empty classes in FIELD.  */
       if (abi_version_at_least (2))
-       record_subobject_offsets (TREE_TYPE (field), 
+       record_subobject_offsets (TREE_TYPE (field),
                                  byte_position(field),
                                  empty_base_offsets,
-                                 /*vbases_p=*/1);
+                                 /*is_data_member=*/true);
 
       /* If a bit-field does not immediately follow another bit-field,
         and yet it starts in the middle of a byte, we have failed to
         comply with the ABI.  */
       if (warn_abi
-         && DECL_C_BIT_FIELD (field) 
+         && DECL_C_BIT_FIELD (field)
+         /* The TREE_NO_WARNING flag gets set by Objective-C when
+            laying out an Objective-C class.  The ObjC ABI differs
+            from the C++ ABI, and so we do not want a warning
+            here.  */
+         && !TREE_NO_WARNING (field)
          && !last_field_was_bitfield
          && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
                                         DECL_FIELD_BIT_OFFSET (field),
                                         bitsize_unit_node)))
-       cp_warning_at ("offset of `%D' is not ABI-compliant and may change in a future version of GCC", 
-                      field);
+       warning (OPT_Wabi, "offset of %q+D is not ABI-compliant and may "
+                "change in a future version of GCC", field);
 
       /* G++ used to use DECL_FIELD_OFFSET as if it were the byte
         offset of the field.  */
-      if (warn_abi 
+      if (warn_abi
          && !tree_int_cst_equal (DECL_FIELD_OFFSET (field),
                                  byte_position (field))
          && contains_empty_class_p (TREE_TYPE (field)))
-       cp_warning_at ("`%D' contains empty classes which may cause base "
-                      "classes to be placed at different locations in a "
-                      "future version of GCC",
-                      field);
+       warning (OPT_Wabi, "%q+D contains empty classes which may cause base "
+                "classes to be placed at different locations in a "
+                "future version of GCC", field);
 
       /* If we needed additional padding after this field, add it
         now.  */
@@ -4746,15 +4733,16 @@ layout_class_type (tree t, tree *virtuals_p)
        {
          tree padding_field;
 
-         padding_field = build_decl (FIELD_DECL, 
+         padding_field = build_decl (FIELD_DECL,
                                      NULL_TREE,
-                                     char_type_node); 
+                                     char_type_node);
          DECL_BIT_FIELD (padding_field) = 1;
          DECL_SIZE (padding_field) = padding;
          DECL_CONTEXT (padding_field) = t;
          DECL_ARTIFICIAL (padding_field) = 1;
+         DECL_IGNORED_P (padding_field) = 1;
          layout_nonempty_base_or_field (rli, padding_field,
-                                        NULL_TREE, 
+                                        NULL_TREE,
                                         empty_base_offsets);
        }
 
@@ -4785,7 +4773,7 @@ layout_class_type (tree t, tree *virtuals_p)
   if (CLASSTYPE_NON_POD_P (t) || CLASSTYPE_EMPTY_P (t))
     {
       base_t = make_node (TREE_CODE (t));
-      
+
       /* Set the size and alignment for the new type.  In G++ 3.2, all
         empty classes were considered to have size zero when used as
         base classes.  */
@@ -4794,7 +4782,8 @@ layout_class_type (tree t, tree *virtuals_p)
          TYPE_SIZE (base_t) = bitsize_zero_node;
          TYPE_SIZE_UNIT (base_t) = size_zero_node;
          if (warn_abi && !integer_zerop (rli_size_unit_so_far (rli)))
-           warning ("layout of classes derived from empty class `%T' "
+           warning (OPT_Wabi,
+                     "layout of classes derived from empty class %qT "
                     "may change in a future version of GCC",
                     t);
        }
@@ -4810,14 +4799,14 @@ layout_class_type (tree t, tree *virtuals_p)
             rli_size_so_far, rather than rli_size_unit_so_far, is
             used to compute TYPE_SIZE_UNIT.  */
          eoc = end_of_class (t, /*include_virtuals_p=*/0);
-         TYPE_SIZE_UNIT (base_t) 
+         TYPE_SIZE_UNIT (base_t)
            = size_binop (MAX_EXPR,
                          convert (sizetype,
                                   size_binop (CEIL_DIV_EXPR,
                                               rli_size_so_far (rli),
                                               bitsize_int (BITS_PER_UNIT))),
                          eoc);
-         TYPE_SIZE (base_t) 
+         TYPE_SIZE (base_t)
            = size_binop (MAX_EXPR,
                          rli_size_so_far (rli),
                          size_binop (MULT_EXPR,
@@ -4833,7 +4822,7 @@ layout_class_type (tree t, tree *virtuals_p)
        if (TREE_CODE (field) == FIELD_DECL)
          {
            *next_field = build_decl (FIELD_DECL,
-                                     DECL_NAME (field), 
+                                     DECL_NAME (field),
                                      TREE_TYPE (field));
            DECL_CONTEXT (*next_field) = base_t;
            DECL_FIELD_OFFSET (*next_field) = DECL_FIELD_OFFSET (field);
@@ -4866,13 +4855,13 @@ layout_class_type (tree t, tree *virtuals_p)
      base subobject fields.  */
   layout_virtual_bases (rli, empty_base_offsets);
 
-  /* Make sure that empty classes are reflected in RLI at this 
+  /* Make sure that empty classes are reflected in RLI at this
      point.  */
   include_empty_classes(rli);
 
   /* Make sure not to create any structures with zero size.  */
   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
-    place_field (rli, 
+    place_field (rli,
                 build_decl (FIELD_DECL, NULL_TREE, char_type_node));
 
   /* Let the back-end lay out the type.  */
@@ -4888,13 +4877,18 @@ layout_class_type (tree t, tree *virtuals_p)
 
   /* Clean up.  */
   splay_tree_delete (empty_base_offsets);
+
+  if (CLASSTYPE_EMPTY_P (t)
+      && tree_int_cst_lt (sizeof_biggest_empty_class, 
+                         TYPE_SIZE_UNIT (t)))
+    sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
 }
 
-/* Returns the virtual function with which the vtable for TYPE is
-   emitted, or NULL_TREE if that heuristic is not applicable to TYPE.  */
+/* Determine the "key method" for the class type indicated by TYPE,
+   and set CLASSTYPE_KEY_METHOD accordingly.  */
 
-static tree
-key_method (tree type)
+void
+determine_key_method (tree type)
 {
   tree method;
 
@@ -4902,16 +4896,23 @@ key_method (tree type)
       || processing_template_decl
       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
       || CLASSTYPE_INTERFACE_KNOWN (type))
-    return NULL_TREE;
+    return;
 
+  /* The key method is the first non-pure virtual function that is not
+     inline at the point of class definition.  On some targets the
+     key function may not be inline; those targets should not call
+     this function until the end of the translation unit.  */
   for (method = TYPE_METHODS (type); method != NULL_TREE;
        method = TREE_CHAIN (method))
     if (DECL_VINDEX (method) != NULL_TREE
        && ! DECL_DECLARED_INLINE_P (method)
        && ! DECL_PURE_VIRTUAL_P (method))
-      return method;
+      {
+       CLASSTYPE_KEY_METHOD (type) = method;
+       break;
+      }
 
-  return NULL_TREE;
+  return;
 }
 
 /* Perform processing required when the definition of T (a class type)
@@ -4924,14 +4925,11 @@ finish_struct_1 (tree t)
   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
   tree virtuals = NULL_TREE;
   int n_fields = 0;
-  tree vfield;
 
   if (COMPLETE_TYPE_P (t))
     {
-      if (IS_AGGR_TYPE (t))
-       error ("redefinition of `%#T'", t);
-      else
-       abort ();
+      gcc_assert (IS_AGGR_TYPE (t));
+      error ("redefinition of %q#T", t);
       popclass ();
       return;
     }
@@ -4942,7 +4940,7 @@ finish_struct_1 (tree t)
   CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
 
   fixup_inline_methods (t);
-  
+
   /* Make assumptions about the class; we'll reset the flags if
      necessary.  */
   CLASSTYPE_EMPTY_P (t) = 1;
@@ -4956,7 +4954,16 @@ finish_struct_1 (tree t)
   /* Find the key method.  */
   if (TYPE_CONTAINS_VPTR_P (t))
     {
-      CLASSTYPE_KEY_METHOD (t) = key_method (t);
+      /* The Itanium C++ ABI permits the key method to be chosen when
+        the class is defined -- even though the key method so
+        selected may later turn out to be an inline function.  On
+        some systems (such as ARM Symbian OS) the key method cannot
+        be determined until the end of the translation unit.  On such
+        systems, we leave CLASSTYPE_KEY_METHOD set to NULL, which
+        will cause the class to be added to KEYED_CLASSES.  Then, in
+        finish_file we will determine the key method.  */
+      if (targetm.cxx.key_method_may_be_inline ())
+       determine_key_method (t);
 
       /* If a polymorphic class has no key method, we may emit the vtable
         in every translation unit where the class definition appears.  */
@@ -4971,25 +4978,6 @@ finish_struct_1 (tree t)
        needs a mode.  */
     compute_record_mode (CLASSTYPE_AS_BASE (t));
 
-  /* Make sure that we get our own copy of the vfield FIELD_DECL.  */
-  vfield = TYPE_VFIELD (t);
-  if (vfield && CLASSTYPE_HAS_PRIMARY_BASE_P (t))
-    {
-      tree primary = CLASSTYPE_PRIMARY_BINFO (t);
-
-      gcc_assert (same_type_p (DECL_FIELD_CONTEXT (vfield),
-                              BINFO_TYPE (primary)));
-      /* The vtable better be at the start.  */
-      gcc_assert (integer_zerop (DECL_FIELD_OFFSET (vfield)));
-      gcc_assert (integer_zerop (BINFO_OFFSET (primary)));
-      
-      vfield = copy_decl (vfield);
-      DECL_FIELD_CONTEXT (vfield) = t;
-      TYPE_VFIELD (t) = vfield;
-    }
-  else
-    gcc_assert (!vfield || DECL_FIELD_CONTEXT (vfield) == t);
-
   virtuals = modify_all_vtables (t, nreverse (virtuals));
 
   /* If necessary, create the primary vtable for this class.  */
@@ -5019,9 +5007,9 @@ finish_struct_1 (tree t)
        = chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
 
       /* Set DECL_VINDEX for all functions declared in this class.  */
-      for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t)); 
-          fn; 
-          fn = TREE_CHAIN (fn), 
+      for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
+          fn;
+          fn = TREE_CHAIN (fn),
             vindex += (TARGET_VTABLE_USES_DESCRIPTORS
                        ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
        {
@@ -5057,8 +5045,8 @@ finish_struct_1 (tree t)
   if (n_fields > 7)
     {
       struct sorted_fields_type *field_vec = GGC_NEWVAR
-         (struct sorted_fields_type,
-          sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
+        (struct sorted_fields_type,
+         sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
       field_vec->len = n_fields;
       add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
       qsort (field_vec->elts, n_fields, sizeof (tree),
@@ -5071,21 +5059,28 @@ finish_struct_1 (tree t)
   /* Make the rtl for any new vtables we have created, and unmark
      the base types we marked.  */
   finish_vtbls (t);
-  
+
   /* Build the VTT for T.  */
   build_vtt (t);
 
-  if (warn_nonvdtor && TYPE_POLYMORPHIC_P (t) && TYPE_HAS_DESTRUCTOR (t)
-      && !DECL_VINDEX (CLASSTYPE_DESTRUCTORS (t)))
-
-    {
-      tree dtor = CLASSTYPE_DESTRUCTORS (t);
-
-      /* Warn only if the dtor is non-private or the class has friends */
-      if (!TREE_PRIVATE (dtor) ||
-         (CLASSTYPE_FRIEND_CLASSES (t) ||
-          DECL_FRIENDLIST (TYPE_MAIN_DECL (t))))
-       warning ("%#T' has virtual functions but non-virtual destructor", t);
+  /* This warning does not make sense for Java classes, since they
+     cannot have destructors.  */
+  if (!TYPE_FOR_JAVA (t) && warn_nonvdtor && TYPE_POLYMORPHIC_P (t))
+    {
+      tree dtor;
+
+      dtor = CLASSTYPE_DESTRUCTORS (t);
+      /* Warn only if the dtor is non-private or the class has
+        friends.  */
+      if (/* An implicitly declared destructor is always public.  And,
+            if it were virtual, we would have created it by now.  */
+         !dtor
+         || (!DECL_VINDEX (dtor)
+             && (!TREE_PRIVATE (dtor)
+                 || CLASSTYPE_FRIEND_CLASSES (t)
+                 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))))
+       warning (0, "%q#T has virtual functions but non-virtual destructor",
+                t);
     }
 
   complete_vars (t);
@@ -5093,10 +5088,15 @@ finish_struct_1 (tree t)
   if (warn_overloaded_virtual)
     warn_hidden (t);
 
+  /* Class layout, assignment of virtual table slots, etc., is now
+     complete.  Give the back end a chance to tweak the visibility of
+     the class or perform any other required target modifications.  */
+  targetm.cxx.adjust_class_at_definition (t);
+
   maybe_suppress_debug_info (t);
 
   dump_class_hierarchy (t);
-  
+
   /* Finish debugging output for this type.  */
   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
 }
@@ -5119,8 +5119,8 @@ unreverse_member_declarations (tree t)
   /* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
      reverse order, so we can't just use nreverse.  */
   prev = NULL_TREE;
-  for (x = TYPE_FIELDS (t); 
-       x && TREE_CODE (x) != TYPE_DECL; 
+  for (x = TYPE_FIELDS (t);
+       x && TREE_CODE (x) != TYPE_DECL;
        x = next)
     {
       next = TREE_CHAIN (x);
@@ -5156,6 +5156,7 @@ finish_struct (tree t, tree attributes)
 
       finish_struct_methods (t);
       TYPE_SIZE (t) = bitsize_zero_node;
+      TYPE_SIZE_UNIT (t) = size_zero_node;
 
       /* We need to emit an error message if this type was used as a parameter
         and it is an abstract type, even if it is a template. We construct
@@ -5164,11 +5165,10 @@ finish_struct (tree t, tree attributes)
         the PARM_DECLS. Note that while the type is being defined,
         CLASSTYPE_PURE_VIRTUALS contains the list of the inline friends
         (see CLASSTYPE_INLINE_FRIENDS) so we need to clear it.  */
-      CLASSTYPE_PURE_VIRTUALS (t) = NULL_TREE;
+      CLASSTYPE_PURE_VIRTUALS (t) = NULL;
       for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
        if (DECL_PURE_VIRTUAL_P (x))
-         CLASSTYPE_PURE_VIRTUALS (t)
-           = tree_cons (NULL_TREE, x, CLASSTYPE_PURE_VIRTUALS (t));
+         VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
       complete_vars (t);
     }
   else
@@ -5243,15 +5243,23 @@ fixed_type_or_null (tree instance, int* nonnull, int* cdtorp)
       return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
 
     case ADDR_EXPR:
+      instance = TREE_OPERAND (instance, 0);
       if (nonnull)
-       *nonnull = 1;
-      return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
+       {
+         /* Just because we see an ADDR_EXPR doesn't mean we're dealing
+            with a real object -- given &p->f, p can still be null.  */
+         tree t = get_base_address (instance);
+         /* ??? Probably should check DECL_WEAK here.  */
+         if (t && DECL_P (t))
+           *nonnull = 1;
+       }
+      return fixed_type_or_null (instance, nonnull, cdtorp);
 
     case COMPONENT_REF:
       /* If this component is really a base class reference, then the field
         itself isn't definitive.  */
       if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
-        return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
+       return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull, cdtorp);
       return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull, cdtorp);
 
     case VAR_DECL:
@@ -5274,30 +5282,30 @@ fixed_type_or_null (tree instance, int* nonnull, int* cdtorp)
          return TREE_TYPE (instance);
        }
       else if (instance == current_class_ptr)
-        {
-          if (nonnull)
-            *nonnull = 1;
-        
-          /* if we're in a ctor or dtor, we know our type.  */
-          if (DECL_LANG_SPECIFIC (current_function_decl)
-              && (DECL_CONSTRUCTOR_P (current_function_decl)
-                  || DECL_DESTRUCTOR_P (current_function_decl)))
-            {
-              if (cdtorp)
-                *cdtorp = 1;
-              return TREE_TYPE (TREE_TYPE (instance));
-            }
-        }
+       {
+         if (nonnull)
+           *nonnull = 1;
+
+         /* if we're in a ctor or dtor, we know our type.  */
+         if (DECL_LANG_SPECIFIC (current_function_decl)
+             && (DECL_CONSTRUCTOR_P (current_function_decl)
+                 || DECL_DESTRUCTOR_P (current_function_decl)))
+           {
+             if (cdtorp)
+               *cdtorp = 1;
+             return TREE_TYPE (TREE_TYPE (instance));
+           }
+       }
       else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
-        {
-          /* Reference variables should be references to objects.  */
-          if (nonnull)
+       {
+         /* Reference variables should be references to objects.  */
+         if (nonnull)
            *nonnull = 1;
-         
+
          /* DECL_VAR_MARKED_P is used to prevent recursion; a
             variable's initializer may refer to the variable
             itself.  */
-         if (TREE_CODE (instance) == VAR_DECL 
+         if (TREE_CODE (instance) == VAR_DECL
              && DECL_INITIAL (instance)
              && !DECL_VAR_MARKED_P (instance))
            {
@@ -5335,7 +5343,7 @@ resolves_to_fixed_type_p (tree instance, int* nonnull)
 {
   tree t = TREE_TYPE (instance);
   int cdtorp = 0;
-  
+
   tree fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
   if (fixed == NULL_TREE)
     return 0;
@@ -5352,9 +5360,10 @@ init_class_processing (void)
 {
   current_class_depth = 0;
   current_class_stack_size = 10;
-  current_class_stack 
-    = xmalloc (current_class_stack_size * sizeof (struct class_stack_node));
-  VARRAY_TREE_INIT (local_classes, 8, "local_classes");
+  current_class_stack
+    = XNEWVEC (struct class_stack_node, current_class_stack_size);
+  local_classes = VEC_alloc (tree, gc, 8);
+  sizeof_biggest_empty_class = size_zero_node;
 
   ridpointers[(int) RID_PUBLIC] = access_public_node;
   ridpointers[(int) RID_PRIVATE] = access_private_node;
@@ -5375,8 +5384,8 @@ restore_class_cache (void)
   push_binding_level (previous_class_level);
   class_binding_level = previous_class_level;
   /* Restore IDENTIFIER_TYPE_VALUE.  */
-  for (type = class_binding_level->type_shadowed; 
-       type; 
+  for (type = class_binding_level->type_shadowed;
+       type;
        type = TREE_CHAIN (type))
     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (type), TREE_TYPE (type));
 }
@@ -5393,23 +5402,26 @@ restore_class_cache (void)
 void
 pushclass (tree type)
 {
+  class_stack_node_t csn;
+
   type = TYPE_MAIN_VARIANT (type);
 
   /* Make sure there is enough room for the new entry on the stack.  */
-  if (current_class_depth + 1 >= current_class_stack_size) 
+  if (current_class_depth + 1 >= current_class_stack_size)
     {
       current_class_stack_size *= 2;
       current_class_stack
-       = xrealloc (current_class_stack,
-                   current_class_stack_size
-                   * sizeof (struct class_stack_node));
+       = XRESIZEVEC (struct class_stack_node, current_class_stack,
+                      current_class_stack_size);
     }
 
   /* Insert a new entry on the class stack.  */
-  current_class_stack[current_class_depth].name = current_class_name;
-  current_class_stack[current_class_depth].type = current_class_type;
-  current_class_stack[current_class_depth].access = current_access_specifier;
-  current_class_stack[current_class_depth].names_used = 0;
+  csn = current_class_stack + current_class_depth;
+  csn->name = current_class_name;
+  csn->type = current_class_type;
+  csn->access = current_access_specifier;
+  csn->names_used = 0;
+  csn->hidden = 0;
   current_class_depth++;
 
   /* Now set up the new type.  */
@@ -5420,8 +5432,8 @@ pushclass (tree type)
 
   /* By default, things in classes are private, while things in
      structures or unions are public.  */
-  current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type) 
-                             ? access_private_node 
+  current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
+                             ? access_private_node
                              : access_public_node);
 
   if (previous_class_level
@@ -5432,14 +5444,12 @@ pushclass (tree type)
       invalidate_class_lookup_cache ();
     }
 
-  if (!previous_class_level 
+  if (!previous_class_level
       || type != previous_class_level->this_entity
       || current_class_depth > 1)
     pushlevel_class ();
   else
     restore_class_cache ();
-  
-  cxx_remember_type_decls (CLASSTYPE_NESTED_UTDS (type));
 }
 
 /* When we exit a toplevel class scope, we save its binding level so
@@ -5451,7 +5461,7 @@ invalidate_class_lookup_cache (void)
 {
   previous_class_level = NULL;
 }
+
 /* Get out of the current class scope. If we were in a class scope
    previously, that is the one popped to.  */
 
@@ -5468,6 +5478,24 @@ popclass (void)
     splay_tree_delete (current_class_stack[current_class_depth].names_used);
 }
 
+/* Mark the top of the class stack as hidden.  */
+
+void
+push_class_stack (void)
+{
+  if (current_class_depth)
+    ++current_class_stack[current_class_depth - 1].hidden;
+}
+
+/* Mark the top of the class stack as un-hidden.  */
+
+void
+pop_class_stack (void)
+{
+  if (current_class_depth)
+    --current_class_stack[current_class_depth - 1].hidden;
+}
+
 /* Returns 1 if current_class_type is either T or a nested type of T.
    We start looking from 1 because entry 0 is from global scope, and has
    no type.  */
@@ -5478,10 +5506,14 @@ currently_open_class (tree t)
   int i;
   if (current_class_type && same_type_p (t, current_class_type))
     return 1;
-  for (i = 1; i < current_class_depth; ++i)
-    if (current_class_stack[i].type
-       && same_type_p (current_class_stack [i].type, t))
-      return 1;
+  for (i = current_class_depth - 1; i > 0; --i)
+    {
+      if (current_class_stack[i].hidden)
+       break;
+      if (current_class_stack[i].type
+         && same_type_p (current_class_stack [i].type, t))
+       return 1;
+    }
   return 0;
 }
 
@@ -5505,8 +5537,12 @@ currently_open_derived_class (tree t)
     return current_class_type;
 
   for (i = current_class_depth - 1; i > 0; --i)
-    if (DERIVED_FROM_P (t, current_class_stack[i].type))
-      return current_class_stack[i].type;
+    {
+      if (current_class_stack[i].hidden)
+       break;
+      if (DERIVED_FROM_P (t, current_class_stack[i].type))
+       return current_class_stack[i].type;
+    }
 
   return NULL_TREE;
 }
@@ -5523,14 +5559,14 @@ push_nested_class (tree type)
   tree context;
 
   /* A namespace might be passed in error cases, like A::B:C.  */
-  if (type == NULL_TREE 
-      || type == error_mark_node 
+  if (type == NULL_TREE
+      || type == error_mark_node
       || TREE_CODE (type) == NAMESPACE_DECL
       || ! IS_AGGR_TYPE (type)
       || TREE_CODE (type) == TEMPLATE_TYPE_PARM
       || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
     return;
-  
+
   context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
 
   if (context && CLASS_TYPE_P (context))
@@ -5555,7 +5591,7 @@ pop_nested_class (void)
 int
 current_lang_depth (void)
 {
-  return VARRAY_ACTIVE_SIZE (current_lang_base);
+  return VEC_length (tree, current_lang_base);
 }
 
 /* Set global variables CURRENT_LANG_NAME to appropriate value
@@ -5564,7 +5600,7 @@ current_lang_depth (void)
 void
 push_lang_context (tree name)
 {
-  VARRAY_PUSH_TREE (current_lang_base, current_lang_name);
+  VEC_safe_push (tree, gc, current_lang_base, current_lang_name);
 
   if (name == lang_name_cplusplus)
     {
@@ -5591,37 +5627,36 @@ push_lang_context (tree name)
       current_lang_name = name;
     }
   else
-    error ("language string `\"%E\"' not recognized", name);
+    error ("language string %<\"%E\"%> not recognized", name);
 }
-  
+
 /* Get out of the current language scope.  */
 
 void
 pop_lang_context (void)
 {
-  current_lang_name = VARRAY_TOP_TREE (current_lang_base);
-  VARRAY_POP (current_lang_base);
+  current_lang_name = VEC_pop (tree, current_lang_base);
 }
 \f
 /* Type instantiation routines.  */
 
 /* Given an OVERLOAD and a TARGET_TYPE, return the function that
    matches the TARGET_TYPE.  If there is no satisfactory match, return
-   error_mark_node, and issue a error & warning messages under control
+   error_mark_node, and issue an error & warning messages under control
    of FLAGS.  Permit pointers to member function if FLAGS permits.  If
    TEMPLATE_ONLY, the name of the overloaded function was a
    template-id, and EXPLICIT_TARGS are the explicitly provided
    template arguments.  */
 
 static tree
-resolve_address_of_overloaded_function (tree target_type, 
+resolve_address_of_overloaded_function (tree target_type,
                                        tree overload,
                                        tsubst_flags_t flags,
                                        bool template_only,
                                        tree explicit_targs)
 {
   /* Here's what the standard says:
-     
+
        [over.over]
 
        If the name is a function template, template argument deduction
@@ -5661,7 +5696,7 @@ resolve_address_of_overloaded_function (tree target_type,
              || TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE);
 
   gcc_assert (is_overloaded_fn (overload));
-  
+
   /* Check that the TARGET_TYPE is reasonable.  */
   if (TYPE_PTRFN_P (target_type))
     /* This is OK.  */;
@@ -5675,15 +5710,15 @@ resolve_address_of_overloaded_function (tree target_type,
       target_type = build_reference_type (target_type);
       is_reference = 1;
     }
-  else 
+  else
     {
       if (flags & tf_error)
-       error ("\
-cannot resolve overloaded function `%D' based on conversion to type `%T'", 
-                 DECL_NAME (OVL_FUNCTION (overload)), target_type);
+       error ("cannot resolve overloaded function %qD based on"
+              " conversion to type %qT",
+              DECL_NAME (OVL_FUNCTION (overload)), target_type);
       return error_mark_node;
     }
-  
+
   /* If we can find a non-template function that matches, we can just
      use it.  There's no point in generating template instantiations
      if we're just going to throw them out anyhow.  But, of course, we
@@ -5707,7 +5742,8 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
               one, or vice versa.  */
            continue;
 
-         /* Ignore anticipated decls of undeclared builtins.  */
+         /* Ignore functions which haven't been explicitly
+            declared.  */
          if (DECL_ANTICIPATED (fn))
            continue;
 
@@ -5718,7 +5754,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
          else if (!is_reference)
            fntype = build_pointer_type (fntype);
 
-         if (can_convert_arg (target_type, fntype, fn))
+         if (can_convert_arg (target_type, fntype, fn, LOOKUP_NORMAL))
            matches = tree_cons (fn, NULL_TREE, matches);
        }
     }
@@ -5726,7 +5762,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
   /* Now, if we've already got a match (or matches), there's no need
      to proceed to the template functions.  But, if we don't have a
      match we need to look at them, too.  */
-  if (!matches) 
+  if (!matches)
     {
       tree target_fn_type;
       tree target_arg_types;
@@ -5744,7 +5780,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
       /* Never do unification on the 'this' parameter.  */
       if (TREE_CODE (target_fn_type) == METHOD_TYPE)
        target_arg_types = TREE_CHAIN (target_arg_types);
-         
+
       for (fns = overload; fns; fns = OVL_NEXT (fns))
        {
          tree fn = OVL_CURRENT (fns);
@@ -5766,7 +5802,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
          targs = make_tree_vec (DECL_NTPARMS (fn));
          if (fn_type_unification (fn, explicit_targs, targs,
                                   target_arg_types, target_ret_type,
-                                  DEDUCE_EXACT, -1) != 0)
+                                  DEDUCE_EXACT, LOOKUP_NORMAL))
            /* Argument deduction failed.  */
            continue;
 
@@ -5779,11 +5815,12 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
          /* See if there's a match.  */
          instantiation_type = TREE_TYPE (instantiation);
          if (is_ptrmem)
-           instantiation_type = 
+           instantiation_type =
              build_ptrmemfunc_type (build_pointer_type (instantiation_type));
          else if (!is_reference)
            instantiation_type = build_pointer_type (instantiation_type);
-         if (can_convert_arg (target_type, instantiation_type, instantiation))
+         if (can_convert_arg (target_type, instantiation_type, instantiation, 
+                              LOOKUP_NORMAL))
            matches = tree_cons (instantiation, fn, matches);
        }
 
@@ -5793,7 +5830,9 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
          tree match = most_specialized_instantiation (matches);
 
          if (match != error_mark_node)
-           matches = tree_cons (match, NULL_TREE, NULL_TREE);
+           matches = tree_cons (TREE_PURPOSE (match), 
+                                NULL_TREE, 
+                                NULL_TREE);
        }
     }
 
@@ -5803,17 +5842,17 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
       /* There were *no* matches.  */
       if (flags & tf_error)
        {
-         error ("no matches converting function `%D' to type `%#T'", 
-                   DECL_NAME (OVL_FUNCTION (overload)),
-                   target_type);
+         error ("no matches converting function %qD to type %q#T",
+                DECL_NAME (OVL_FUNCTION (overload)),
+                target_type);
 
          /* print_candidates expects a chain with the functions in
-             TREE_VALUE slots, so we cons one up here (we're losing anyway,
-             so why be clever?).  */
-          for (; overload; overload = OVL_NEXT (overload))
-            matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
+            TREE_VALUE slots, so we cons one up here (we're losing anyway,
+            so why be clever?).  */
+         for (; overload; overload = OVL_NEXT (overload))
+           matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
                                 matches);
-          
+
          print_candidates (matches);
        }
       return error_mark_node;
@@ -5826,7 +5865,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
        {
          tree match;
 
-         error ("converting overloaded function `%D' to type `%#T' is ambiguous", 
+         error ("converting overloaded function %qD to type %q#T is ambiguous",
                    DECL_NAME (OVL_FUNCTION (overload)),
                    target_type);
 
@@ -5837,7 +5876,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
 
          print_candidates (matches);
        }
-      
+
       return error_mark_node;
     }
 
@@ -5848,16 +5887,16 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
       && !(flags & tf_ptrmem_ok) && !flag_ms_extensions)
     {
       static int explained;
-      
+
       if (!(flags & tf_error))
-        return error_mark_node;
+       return error_mark_node;
 
-      pedwarn ("assuming pointer to member `%D'", fn);
+      pedwarn ("assuming pointer to member %qD", fn);
       if (!explained)
-        {
-          pedwarn ("(a pointer to member can only be formed with `&%E')", fn);
-          explained = 1;
-        }
+       {
+         pedwarn ("(a pointer to member can only be formed with %<&%E%>)", fn);
+         explained = 1;
+       }
     }
 
   /* If we're doing overload resolution purely for the purpose of
@@ -5886,7 +5925,7 @@ cannot resolve overloaded function `%D' based on conversion to type `%T'",
    we complain on errors.  If we are not complaining, never modify rhs,
    as overload resolution wants to try many possible instantiations, in
    the hope that at least one will work.
-   
+
    For non-recursive calls, LHSTYPE should be a function, pointer to
    function, or a pointer to member function.  */
 
@@ -5894,9 +5933,9 @@ tree
 instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
 {
   tsubst_flags_t flags_in = flags;
-  
+
   flags &= ~tf_ptrmem_ok;
-  
+
   if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
     {
       if (flags & tf_error)
@@ -5908,7 +5947,7 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
     {
       if (same_type_p (lhstype, TREE_TYPE (rhs)))
        return rhs;
-      if (flag_ms_extensions 
+      if (flag_ms_extensions
          && TYPE_PTRMEMFUNC_P (lhstype)
          && !TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
        /* Microsoft allows `A::f' to be resolved to a
@@ -5917,7 +5956,7 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
       else
        {
          if (flags & tf_error)
-           error ("argument of type `%T' does not match `%T'",
+           error ("argument of type %qT does not match %qT",
                   TREE_TYPE (rhs), lhstype);
          return error_mark_node;
        }
@@ -5926,6 +5965,15 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
   if (TREE_CODE (rhs) == BASELINK)
     rhs = BASELINK_FUNCTIONS (rhs);
 
+  /* If we are in a template, and have a NON_DEPENDENT_EXPR, we cannot
+     deduce any type information.  */
+  if (TREE_CODE (rhs) == NON_DEPENDENT_EXPR)
+    {
+      if (flags & tf_error)
+       error ("not enough type information");
+      return error_mark_node;
+    }
+
   /* We don't overwrite rhs if it is an overloaded function.
      Copying it would destroy the tree link.  */
   if (TREE_CODE (rhs) != OVERLOAD)
@@ -5942,8 +5990,7 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
     case CONVERT_EXPR:
     case SAVE_EXPR:
     case CONSTRUCTOR:
-      abort ();
-      return error_mark_node;
+      gcc_unreachable ();
 
     case INDIRECT_REF:
     case ARRAY_REF:
@@ -5967,14 +6014,15 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
 
     case COMPONENT_REF:
       {
-       tree addr = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
+       tree member = TREE_OPERAND (rhs, 1);
 
-       if (addr != error_mark_node
+       member = instantiate_type (lhstype, member, flags);
+       if (member != error_mark_node
            && TREE_SIDE_EFFECTS (TREE_OPERAND (rhs, 0)))
          /* Do not lose object's side effects.  */
-         addr = build2 (COMPOUND_EXPR, TREE_TYPE (addr),
-                        TREE_OPERAND (rhs, 0), addr);
-       return addr;
+         return build2 (COMPOUND_EXPR, TREE_TYPE (member),
+                        TREE_OPERAND (rhs, 0), member);
+       return member;
       }
 
     case OFFSET_REF:
@@ -6001,21 +6049,14 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
 
     case OVERLOAD:
     case FUNCTION_DECL:
-      return 
+      return
        resolve_address_of_overloaded_function (lhstype, rhs, flags_in,
                                                /*template_only=*/false,
                                                /*explicit_targs=*/NULL_TREE);
 
-    case TREE_LIST:
-      /* Now we should have a baselink.  */
-      gcc_assert (BASELINK_P (rhs));
-
-      return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs), flags);
-
     case CALL_EXPR:
       /* This is too hard for now.  */
-      abort ();
-      return error_mark_node;
+      gcc_unreachable ();
 
     case PLUS_EXPR:
     case MINUS_EXPR:
@@ -6111,12 +6152,12 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
 
       TREE_TYPE (rhs) = lhstype;
       return rhs;
-      
+
     case ADDR_EXPR:
     {
       if (PTRMEM_OK_P (rhs))
-        flags |= tf_ptrmem_ok;
-      
+       flags |= tf_ptrmem_ok;
+
       return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
     }
 
@@ -6124,9 +6165,9 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
       return error_mark_node;
 
     default:
-      abort ();
-      return error_mark_node;
+      gcc_unreachable ();
     }
+  return error_mark_node;
 }
 \f
 /* Return the name of the virtual function pointer field
@@ -6151,9 +6192,10 @@ get_vfield_name (tree type)
          || !TYPE_CONTAINS_VPTR_P (BINFO_TYPE (base_binfo)))
        break;
     }
-  
+
   type = BINFO_TYPE (binfo);
-  buf = alloca (sizeof (VFIELD_NAME_FORMAT) + TYPE_NAME_LENGTH (type) + 2);
+  buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
+                         + TYPE_NAME_LENGTH (type) + 2);
   sprintf (buf, VFIELD_NAME_FORMAT,
           IDENTIFIER_POINTER (constructor_name (type)));
   return get_identifier (buf);
@@ -6177,7 +6219,7 @@ print_class_statistics (void)
 
 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
    according to [class]:
-                                          The class-name is also inserted
+                                         The class-name is also inserted
    into  the scope of the class itself.  For purposes of access checking,
    the inserted class name is treated as if it were a public member name.  */
 
@@ -6250,35 +6292,6 @@ contains_empty_class_p (tree type)
   return false;
 }
 
-/* Find the enclosing class of the given NODE.  NODE can be a *_DECL or
-   a *_TYPE node.  NODE can also be a local class.  */
-
-tree
-get_enclosing_class (tree type)
-{
-  tree node = type;
-
-  while (node && TREE_CODE (node) != NAMESPACE_DECL)
-    {
-      switch (TREE_CODE_CLASS (TREE_CODE (node)))
-       {
-       case 'd':
-         node = DECL_CONTEXT (node);
-         break;
-
-       case 't':
-         if (node != type)
-           return node;
-         node = TYPE_CONTEXT (node);
-         break;
-
-       default:
-         abort ();
-       }
-    }
-  return NULL_TREE;
-}
-
 /* Note that NAME was looked up while the current class was being
    defined and that the result of that lookup was DECL.  */
 
@@ -6291,10 +6304,10 @@ maybe_note_name_used_in_class (tree name, tree decl)
   if (!(innermost_scope_kind() == sk_class
        && TYPE_BEING_DEFINED (current_class_type)))
     return;
-  
+
   /* If there's already a binding for this NAME, then we don't have
      anything to worry about.  */
-  if (lookup_member (current_class_type, name, 
+  if (lookup_member (current_class_type, name,
                     /*protect=*/0, /*want_type=*/false))
     return;
 
@@ -6304,7 +6317,7 @@ maybe_note_name_used_in_class (tree name, tree decl)
   names_used = current_class_stack[current_class_depth - 1].names_used;
 
   splay_tree_insert (names_used,
-                    (splay_tree_key) name, 
+                    (splay_tree_key) name,
                     (splay_tree_value) decl);
 }
 
@@ -6318,7 +6331,7 @@ note_name_declared_in_class (tree name, tree decl)
   splay_tree_node n;
 
   /* Look to see if we ever used this name.  */
-  names_used 
+  names_used
     = current_class_stack[current_class_depth - 1].names_used;
   if (!names_used)
     return;
@@ -6327,14 +6340,13 @@ note_name_declared_in_class (tree name, tree decl)
   if (n)
     {
       /* [basic.scope.class]
-        
+
         A name N used in a class S shall refer to the same declaration
         in its context and when re-evaluated in the completed scope of
         S.  */
-      error ("declaration of `%#D'", decl);
-      cp_error_at ("changes meaning of `%D' from `%+#D'", 
-                  DECL_NAME (OVL_CURRENT (decl)),
-                  (tree) n->value);
+      error ("declaration of %q#D", decl);
+      error ("changes meaning of %qD from %q+#D",
+            DECL_NAME (OVL_CURRENT (decl)), (tree) n->value);
     }
 }
 
@@ -6365,18 +6377,16 @@ get_vtbl_decl_for_binfo (tree binfo)
    BINFO in the complete object.  Check BINFO_PRIMARY_P or
    BINFO_LOST_PRIMARY_P to be sure.  */
 
-tree
+static tree
 get_primary_binfo (tree binfo)
 {
   tree primary_base;
-  tree result;
-  
+
   primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
   if (!primary_base)
     return NULL_TREE;
 
-  result = copied_binfo (primary_base, binfo);
-  return result;
+  return copied_binfo (primary_base, binfo);
 }
 
 /* If INDENTED_P is zero, indent to INDENT. Return nonzero.  */
@@ -6396,15 +6406,15 @@ maybe_indent_hierarchy (FILE * stream, int indent, int indented_p)
 
 static tree
 dump_class_hierarchy_r (FILE *stream,
-                        int flags,
-                        tree binfo,
-                        tree igo,
-                        int indent)
+                       int flags,
+                       tree binfo,
+                       tree igo,
+                       int indent)
 {
   int indented = 0;
   tree base_binfo;
   int i;
-  
+
   indented = maybe_indent_hierarchy (stream, indent, 0);
   fprintf (stream, "%s (0x%lx) ",
           type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER),
@@ -6415,7 +6425,7 @@ dump_class_hierarchy_r (FILE *stream,
       return igo;
     }
   igo = TREE_CHAIN (binfo);
-  
+
   fprintf (stream, HOST_WIDE_INT_PRINT_DEC,
           tree_low_cst (BINFO_OFFSET (binfo), 0));
   if (is_empty_class (BINFO_TYPE (binfo)))
@@ -6446,7 +6456,7 @@ dump_class_hierarchy_r (FILE *stream,
   if (!(flags & TDF_SLIM))
     {
       int indented = 0;
-      
+
       if (BINFO_SUBVTT_INDEX (binfo))
        {
          indented = maybe_indent_hierarchy (stream, indent + 3, indented);
@@ -6475,14 +6485,14 @@ dump_class_hierarchy_r (FILE *stream,
                   expr_as_string (BINFO_VTABLE (binfo),
                                   TFF_PLAIN_IDENTIFIER));
        }
-      
+
       if (indented)
        fprintf (stream, "\n");
     }
 
   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
     igo = dump_class_hierarchy_r (stream, flags, base_binfo, igo, indent + 2);
-  
+
   return igo;
 }
 
@@ -6506,7 +6516,7 @@ dump_class_hierarchy_1 (FILE *stream, int flags, tree t)
 
 /* Debug interface to hierarchy dumping.  */
 
-extern void
+void
 debug_class (tree t)
 {
   dump_class_hierarchy_1 (stderr, TDF_SLIM, t);
@@ -6528,8 +6538,8 @@ dump_class_hierarchy (tree t)
 static void
 dump_array (FILE * stream, tree decl)
 {
-  tree inits;
-  int ix;
+  tree value;
+  unsigned HOST_WIDE_INT ix;
   HOST_WIDE_INT elt;
   tree size = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (decl)));
 
@@ -6541,10 +6551,10 @@ dump_array (FILE * stream, tree decl)
                           TFF_PLAIN_IDENTIFIER));
   fprintf (stream, "\n");
 
-  for (ix = 0, inits = CONSTRUCTOR_ELTS (DECL_INITIAL (decl));
-       inits; ix++, inits = TREE_CHAIN (inits))
+  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
+                             ix, value)
     fprintf (stream, "%-4ld  %s\n", (long)(ix * elt),
-            expr_as_string (TREE_VALUE (inits), TFF_PLAIN_IDENTIFIER));
+            expr_as_string (value, TFF_PLAIN_IDENTIFIER));
 }
 
 static void
@@ -6559,7 +6569,7 @@ dump_vtable (tree t, tree binfo, tree vtable)
   if (!(flags & TDF_SLIM))
     {
       int ctor_vtbl_p = TYPE_BINFO (t) != binfo;
-      
+
       fprintf (stream, "%s for %s",
               ctor_vtbl_p ? "Construction vtable" : "Vtable",
               type_as_string (BINFO_TYPE (binfo), TFF_PLAIN_IDENTIFIER));
@@ -6573,7 +6583,7 @@ dump_vtable (tree t, tree binfo, tree vtable)
       dump_array (stream, vtable);
       fprintf (stream, "\n");
     }
-  
+
   dump_end (TDI_class, stream);
 }
 
@@ -6593,7 +6603,7 @@ dump_vtt (tree t, tree vtt)
       dump_array (stream, vtt);
       fprintf (stream, "\n");
     }
-  
+
   dump_end (TDI_class, stream);
 }
 
@@ -6605,7 +6615,7 @@ dump_thunk (FILE *stream, int indent, tree thunk)
   static const char spaces[] = "        ";
   tree name = DECL_NAME (thunk);
   tree thunks;
-      
+
   fprintf (stream, "%.*s%p %s %s", indent, spaces,
           (void *)thunk,
           !DECL_THUNK_P (thunk) ? "function"
@@ -6636,7 +6646,7 @@ dump_thunk (FILE *stream, int indent, tree thunk)
 
 /* Dump the thunks for FN.  */
 
-extern void
+void
 debug_thunks (tree fn)
 {
   dump_thunk (stderr, 0, fn);
@@ -6658,7 +6668,7 @@ finish_vtbls (tree t)
   list = build_tree_list (BINFO_VTABLE (TYPE_BINFO (t)), NULL_TREE);
   accumulate_vtbl_inits (TYPE_BINFO (t), TYPE_BINFO (t),
                         TYPE_BINFO (t), t, list);
-  
+
   /* Then come the virtual bases, also in inheritance graph order.  */
   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
     {
@@ -6680,23 +6690,13 @@ initialize_vtable (tree binfo, tree inits)
 
   layout_vtable_decl (binfo, list_length (inits));
   decl = get_vtbl_decl_for_binfo (binfo);
-  initialize_array (decl, inits);
+  initialize_artificial_var (decl, inits);
   dump_vtable (BINFO_TYPE (binfo), binfo, decl);
 }
 
-/* Initialize DECL (a declaration for a namespace-scope array) with
-   the INITS.  */
-
-static void
-initialize_array (tree decl, tree inits)
-{
-  DECL_INITIAL (decl) = build_constructor (NULL_TREE, inits);
-  cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0);
-}
-
 /* Build the VTT (virtual table table) for T.
    A class requires a VTT if it has virtual bases.
-   
+
    This holds
    1 - primary virtual pointer for complete object T
    2 - secondary VTTs for each direct non-virtual base of T which requires a
@@ -6704,7 +6704,7 @@ initialize_array (tree decl, tree inits)
    3 - secondary virtual pointers for each direct or indirect base of T which
        has virtual bases or is reachable via a virtual path from T.
    4 - secondary VTTs for each direct or indirect virtual base of T.
-   
+
    Secondary VTTs look like complete object VTTs without part 4.  */
 
 static void
@@ -6727,10 +6727,10 @@ build_vtt (tree t)
   /* Figure out the type of the VTT.  */
   type = build_index_type (size_int (list_length (inits) - 1));
   type = build_cplus_array_type (const_ptr_type_node, type);
-                                
+
   /* Now, build the VTT object itself.  */
-  vtt = build_vtable (t, get_vtt_name (t), type);
-  initialize_array (vtt, inits);
+  vtt = build_vtable (t, mangle_vtt_for_type (t), type);
+  initialize_artificial_var (vtt, inits);
   /* Add the VTT to the vtables list.  */
   TREE_CHAIN (vtt) = TREE_CHAIN (CLASSTYPE_VTABLES (t));
   TREE_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
@@ -6762,6 +6762,22 @@ binfo_ctor_vtable (tree binfo)
   return vt;
 }
 
+/* Data for secondary VTT initialization.  */
+typedef struct secondary_vptr_vtt_init_data_s
+{
+  /* Is this the primary VTT? */
+  bool top_level_p;
+
+  /* Current index into the VTT.  */
+  tree index;
+
+  /* TREE_LIST of initializers built up.  */
+  tree inits;
+
+  /* The type being constructed by this secondary VTT.  */
+  tree type_being_constructed;
+} secondary_vptr_vtt_init_data;
+
 /* Recursively build the VTT-initializer for BINFO (which is in the
    hierarchy dominated by T).  INITS points to the end of the initializer
    list to date.  INDEX is the VTT index where the next element will be
@@ -6771,16 +6787,17 @@ binfo_ctor_vtable (tree binfo)
    vtables for the BINFO-in-T variant.  */
 
 static tree *
-build_vtt_inits (tree binfo, tree t, tree* inits, tree* index)
+build_vtt_inits (tree binfo, tree t, tree *inits, tree *index)
 {
   int i;
   tree b;
   tree init;
   tree secondary_vptrs;
-  int top_level_p = same_type_p (TREE_TYPE (binfo), t);
+  secondary_vptr_vtt_init_data data;
+  int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
 
   /* We only need VTTs for subobjects with virtual bases.  */
-  if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
+  if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
     return inits;
 
   /* We need to use a construction vtable if this is not the primary
@@ -6803,35 +6820,28 @@ build_vtt_inits (tree binfo, tree t, tree* inits, tree* index)
       BINFO_VPTR_INDEX (binfo) = *index;
     }
   *index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
-                      
+
   /* Recursively add the secondary VTTs for non-virtual bases.  */
   for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
     if (!BINFO_VIRTUAL_P (b))
-      inits = build_vtt_inits (BINFO_BASE_BINFO (binfo, i), t, inits, index);
-      
+      inits = build_vtt_inits (b, t, inits, index);
+
   /* Add secondary virtual pointers for all subobjects of BINFO with
      either virtual bases or reachable along a virtual path, except
      subobjects that are non-virtual primary bases.  */
-  secondary_vptrs = tree_cons (t, NULL_TREE, BINFO_TYPE (binfo));
-  TREE_TYPE (secondary_vptrs) = *index;
-  VTT_TOP_LEVEL_P (secondary_vptrs) = top_level_p;
-  VTT_MARKED_BINFO_P (secondary_vptrs) = 0;
-  
-  dfs_walk_real (binfo,
-                dfs_build_secondary_vptr_vtt_inits,
-                NULL,
-                dfs_ctor_vtable_bases_queue_p,
-                secondary_vptrs);
-  VTT_MARKED_BINFO_P (secondary_vptrs) = 1;
-  dfs_walk (binfo, dfs_unmark, dfs_ctor_vtable_bases_queue_p,
-            secondary_vptrs);
+  data.top_level_p = top_level_p;
+  data.index = *index;
+  data.inits = NULL;
+  data.type_being_constructed = BINFO_TYPE (binfo);
 
-  *index = TREE_TYPE (secondary_vptrs);
+  dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
+
+  *index = data.index;
 
   /* The secondary vptrs come back in reverse order.  After we reverse
      them, and add the INITS, the last init will be the first element
      of the chain.  */
-  secondary_vptrs = TREE_VALUE (secondary_vptrs);
+  secondary_vptrs = data.inits;
   if (secondary_vptrs)
     {
       *inits = nreverse (secondary_vptrs);
@@ -6839,130 +6849,101 @@ build_vtt_inits (tree binfo, tree t, tree* inits, tree* index)
       gcc_assert (*inits == NULL_TREE);
     }
 
-  /* Add the secondary VTTs for virtual bases.  */
   if (top_level_p)
+    /* Add the secondary VTTs for virtual bases in inheritance graph
+       order.  */
     for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
       {
        if (!BINFO_VIRTUAL_P (b))
          continue;
-       
+
        inits = build_vtt_inits (b, t, inits, index);
       }
-
-  if (!top_level_p)
-    {
-      tree data = tree_cons (t, binfo, NULL_TREE);
-      VTT_TOP_LEVEL_P (data) = 0;
-      VTT_MARKED_BINFO_P (data) = 0;
-      
-      dfs_walk (binfo, dfs_fixup_binfo_vtbls,
-               dfs_ctor_vtable_bases_queue_p,
-               data);
-    }
+  else
+    /* Remove the ctor vtables we created.  */
+    dfs_walk_all (binfo, dfs_fixup_binfo_vtbls, NULL, binfo);
 
   return inits;
 }
 
 /* Called from build_vtt_inits via dfs_walk.  BINFO is the binfo for the base
-   in most derived. DATA is a TREE_LIST who's TREE_CHAIN is the type of the
-   base being constructed whilst this secondary vptr is live.  The
-   TREE_TOP_LEVEL flag indicates that this is the primary VTT.  */
+   in most derived. DATA is a SECONDARY_VPTR_VTT_INIT_DATA structure.  */
 
 static tree
-dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data)
+dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
 {
-  tree l; 
-  tree t;
-  tree init;
-  tree index;
-  int top_level_p;
-
-  l = (tree) data;
-  t = TREE_CHAIN (l);
-  top_level_p = VTT_TOP_LEVEL_P (l);
-  
-  BINFO_MARKED (binfo) = 1;
+  secondary_vptr_vtt_init_data *data = (secondary_vptr_vtt_init_data *)data_;
 
   /* We don't care about bases that don't have vtables.  */
   if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
-    return NULL_TREE;
+    return dfs_skip_bases;
 
-  /* We're only interested in proper subobjects of T.  */
-  if (same_type_p (BINFO_TYPE (binfo), t))
+  /* We're only interested in proper subobjects of the type being
+     constructed.  */
+  if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->type_being_constructed))
     return NULL_TREE;
 
+  /* We're only interested in bases with virtual bases or reachable
+     via a virtual path from the type being constructed.  */
+  if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
+       || binfo_via_virtual (binfo, data->type_being_constructed)))
+    return dfs_skip_bases;
+
   /* We're not interested in non-virtual primary bases.  */
   if (!BINFO_VIRTUAL_P (binfo) && BINFO_PRIMARY_P (binfo))
     return NULL_TREE;
 
-  /* If BINFO has virtual bases or is reachable via a virtual path
-     from T, it'll have a secondary vptr.  */
-  if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))
-      && !binfo_via_virtual (binfo, t))
-    return NULL_TREE;
-
   /* Record the index where this secondary vptr can be found.  */
-  index = TREE_TYPE (l);
-  if (top_level_p)
+  if (data->top_level_p)
     {
       gcc_assert (!BINFO_VPTR_INDEX (binfo));
-      BINFO_VPTR_INDEX (binfo) = index;
-    }
-  TREE_TYPE (l) = size_binop (PLUS_EXPR, index, 
-                             TYPE_SIZE_UNIT (ptr_type_node));
+      BINFO_VPTR_INDEX (binfo) = data->index;
 
-  /* Add the initializer for the secondary vptr itself.  */
-  if (top_level_p && BINFO_VIRTUAL_P (binfo))
-    {
-      /* It's a primary virtual base, and this is not the construction
-         vtable. Find the base this is primary of in the inheritance graph,
-         and use that base's vtable now.  */
-      while (BINFO_PRIMARY_P (binfo))
-        binfo = BINFO_INHERITANCE_CHAIN (binfo);
+      if (BINFO_VIRTUAL_P (binfo))
+       {
+         /* It's a primary virtual base, and this is not a
+            construction vtable.  Find the base this is primary of in
+            the inheritance graph, and use that base's vtable
+            now.  */
+         while (BINFO_PRIMARY_P (binfo))
+           binfo = BINFO_INHERITANCE_CHAIN (binfo);
+       }
     }
-  init = binfo_ctor_vtable (binfo);
-  TREE_VALUE (l) = tree_cons (NULL_TREE, init, TREE_VALUE (l));
 
-  return NULL_TREE;
-}
+  /* Add the initializer for the secondary vptr itself.  */
+  data->inits = tree_cons (NULL_TREE, binfo_ctor_vtable (binfo), data->inits);
 
-/* dfs_walk_real predicate for building vtables. DATA is a TREE_LIST,
-   VTT_MARKED_BINFO_P indicates whether marked or unmarked bases
-   should be walked.  TREE_PURPOSE is the TREE_TYPE that dominates the
-   hierarchy.  */
+  /* Advance the vtt index.  */
+  data->index = size_binop (PLUS_EXPR, data->index,
+                           TYPE_SIZE_UNIT (ptr_type_node));
 
-static tree
-dfs_ctor_vtable_bases_queue_p (tree derived, int ix,
-                              void* data)
-{
-  tree binfo = BINFO_BASE_BINFO (derived, ix);
-  
-  if (!BINFO_MARKED (binfo) == VTT_MARKED_BINFO_P ((tree) data))
-    return NULL_TREE;
-  return binfo;
+  return NULL_TREE;
 }
 
-/* Called from build_vtt_inits via dfs_walk. After building constructor
-   vtables and generating the sub-vtt from them, we need to restore the
-   BINFO_VTABLES that were scribbled on.  DATA is a TREE_LIST whose
-   TREE_VALUE is the TREE_TYPE of the base whose sub vtt was generated.  */
+/* Called from build_vtt_inits via dfs_walk. After building
+   constructor vtables and generating the sub-vtt from them, we need
+   to restore the BINFO_VTABLES that were scribbled on.  DATA is the
+   binfo of the base whose sub vtt was generated.  */
 
 static tree
 dfs_fixup_binfo_vtbls (tree binfo, void* data)
 {
-  BINFO_MARKED (binfo) = 0;
+  tree vtable = BINFO_VTABLE (binfo);
 
-  /* We don't care about bases that don't have vtables.  */
-  if (!TYPE_VFIELD (BINFO_TYPE (binfo)))
+  if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
+    /* If this class has no vtable, none of its bases do.  */
+    return dfs_skip_bases;
+
+  if (!vtable)
+    /* This might be a primary base, so have no vtable in this
+       hierarchy.  */
     return NULL_TREE;
 
   /* If we scribbled the construction vtable vptr into BINFO, clear it
      out now.  */
-  if (BINFO_VTABLE (binfo)
-      && TREE_CODE (BINFO_VTABLE (binfo)) == TREE_LIST
-      && (TREE_PURPOSE (BINFO_VTABLE (binfo)) 
-         == TREE_VALUE ((tree) data)))
-    BINFO_VTABLE (binfo) = TREE_CHAIN (BINFO_VTABLE (binfo));
+  if (TREE_CODE (vtable) == TREE_LIST
+      && (TREE_PURPOSE (vtable) == (tree) data))
+    BINFO_VTABLE (binfo) = TREE_CHAIN (vtable);
 
   return NULL_TREE;
 }
@@ -6985,19 +6966,20 @@ build_ctor_vtbl_group (tree binfo, tree t)
   if (IDENTIFIER_GLOBAL_VALUE (id))
     return;
 
-  gcc_assert (!same_type_p (BINFO_TYPE (binfo), t));
+  gcc_assert (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t));
   /* Build a version of VTBL (with the wrong type) for use in
      constructing the addresses of secondary vtables in the
      construction vtable group.  */
   vtbl = build_vtable (t, id, ptr_type_node);
+  DECL_CONSTRUCTION_VTABLE_P (vtbl) = 1;
   list = build_tree_list (vtbl, NULL_TREE);
   accumulate_vtbl_inits (binfo, TYPE_BINFO (TREE_TYPE (binfo)),
                         binfo, t, list);
 
   /* Add the vtables for each of our virtual bases using the vbase in T
      binfo.  */
-  for (vbase = TYPE_BINFO (BINFO_TYPE (binfo)); 
-       vbase; 
+  for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
+       vbase;
        vbase = TREE_CHAIN (vbase))
     {
       tree b;
@@ -7005,7 +6987,7 @@ build_ctor_vtbl_group (tree binfo, tree t)
       if (!BINFO_VIRTUAL_P (vbase))
        continue;
       b = copied_binfo (vbase, binfo);
-      
+
       accumulate_vtbl_inits (b, vbase, binfo, t, list);
     }
   inits = TREE_VALUE (list);
@@ -7017,7 +6999,7 @@ build_ctor_vtbl_group (tree binfo, tree t)
 
   /* Initialize the construction vtable.  */
   CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
-  initialize_array (vtbl, inits);
+  initialize_artificial_var (vtbl, inits);
   dump_vtable (t, binfo, vtbl);
 }
 
@@ -7033,34 +7015,34 @@ build_ctor_vtbl_group (tree binfo, tree t)
 
 static void
 accumulate_vtbl_inits (tree binfo,
-                       tree orig_binfo,
-                       tree rtti_binfo,
-                       tree t,
-                       tree inits)
+                      tree orig_binfo,
+                      tree rtti_binfo,
+                      tree t,
+                      tree inits)
 {
   int i;
   tree base_binfo;
-  int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
+  int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
 
-  gcc_assert (same_type_p (BINFO_TYPE (binfo), BINFO_TYPE (orig_binfo)));
+  gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (orig_binfo)));
 
   /* If it doesn't have a vptr, we don't do anything.  */
   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
     return;
-  
+
   /* If we're building a construction vtable, we're not interested in
      subobjects that don't require construction vtables.  */
-  if (ctor_vtbl_p 
-      && !TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))
+  if (ctor_vtbl_p
+      && !CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
       && !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
     return;
 
   /* Build the initializers for the BINFO-in-T vtable.  */
-  TREE_VALUE (inits) 
+  TREE_VALUE (inits)
     = chainon (TREE_VALUE (inits),
               dfs_accumulate_vtbl_inits (binfo, orig_binfo,
                                          rtti_binfo, t, inits));
-                     
+
   /* Walk the BINFO and its bases.  We walk in preorder so that as we
      initialize each vtable we can figure out at what offset the
      secondary vtable lies from the primary vtable.  We can't use
@@ -7083,14 +7065,14 @@ accumulate_vtbl_inits (tree binfo,
 
 static tree
 dfs_accumulate_vtbl_inits (tree binfo,
-                           tree orig_binfo,
-                           tree rtti_binfo,
-                           tree t,
-                           tree l)
+                          tree orig_binfo,
+                          tree rtti_binfo,
+                          tree t,
+                          tree l)
 {
   tree inits = NULL_TREE;
   tree vtbl = NULL_TREE;
-  int ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
+  int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
 
   if (ctor_vtbl_p
       && BINFO_VIRTUAL_P (orig_binfo) && BINFO_PRIMARY_P (orig_binfo))
@@ -7102,14 +7084,14 @@ dfs_accumulate_vtbl_inits (tree binfo,
         primary, we still need a VTT entry for the vtable, but it
         should point to the ctor vtable for the base it is a
         primary for within the sub-hierarchy of RTTI_BINFO.
-             
+
         There are three possible cases:
-             
+
         1) We are in the same place.
         2) We are a primary base within a lost primary virtual base of
         RTTI_BINFO.
         3) We are primary to something not a base of RTTI_BINFO.  */
-         
+
       tree b;
       tree last = NULL_TREE;
 
@@ -7129,7 +7111,7 @@ dfs_accumulate_vtbl_inits (tree binfo,
        if (BINFO_VIRTUAL_P (b) || b == rtti_binfo)
          break;
     found:
-      
+
       /* If we found RTTI_BINFO, this is case 1.  If we found a virtual
         base B and it is a base of RTTI_BINFO, this is case 2.  In
         either case, we share our vtable with LAST, i.e. the
@@ -7181,6 +7163,8 @@ dfs_accumulate_vtbl_inits (tree binfo,
   return inits;
 }
 
+static GTY(()) tree abort_fndecl_addr;
+
 /* Construct the initializer for BINFO's virtual function table.  BINFO
    is part of the hierarchy dominated by T.  If we're building a
    construction vtable, the ORIG_BINFO is the binfo we should use to
@@ -7195,7 +7179,7 @@ dfs_accumulate_vtbl_inits (tree binfo,
    The value returned is a TREE_LIST suitable for wrapping in a
    CONSTRUCTOR to use as the DECL_INITIAL for a vtable.  If
    NON_FN_ENTRIES_P is not NULL, *NON_FN_ENTRIES_P is set to the
-   number of non-function entries in the vtable.  
+   number of non-function entries in the vtable.
 
    It might seem that this function should never be called with a
    BINFO for which BINFO_PRIMARY_P holds, the vtable for such a
@@ -7206,26 +7190,26 @@ dfs_accumulate_vtbl_inits (tree binfo,
 
 static tree
 build_vtbl_initializer (tree binfo,
-                        tree orig_binfo,
-                        tree t,
-                        tree rtti_binfo,
-                        int* non_fn_entries_p)
+                       tree orig_binfo,
+                       tree t,
+                       tree rtti_binfo,
+                       int* non_fn_entries_p)
 {
   tree v, b;
   tree vfun_inits;
   vtbl_init_data vid;
   unsigned ix;
   tree vbinfo;
-  VEC (tree) *vbases;
-  
+  VEC(tree,gc) *vbases;
+
   /* Initialize VID.  */
   memset (&vid, 0, sizeof (vid));
   vid.binfo = binfo;
   vid.derived = t;
   vid.rtti_binfo = rtti_binfo;
   vid.last_init = &vid.inits;
-  vid.primary_vtbl_p = (binfo == TYPE_BINFO (t));
-  vid.ctor_vtbl_p = !same_type_p (BINFO_TYPE (rtti_binfo), t);
+  vid.primary_vtbl_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
+  vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   vid.generate_vcall_entries = true;
   /* The first vbase or vcall offset is at index -3 in the vtable.  */
   vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
@@ -7236,10 +7220,10 @@ build_vtbl_initializer (tree binfo,
   /* Create an array for keeping track of the functions we've
      processed.  When we see multiple functions with the same
      signature, we share the vcall offsets.  */
-  VARRAY_TREE_INIT (vid.fns, 32, "fns");
+  vid.fns = VEC_alloc (tree, gc, 32);
   /* Add the vcall and vbase offset entries.  */
   build_vcall_and_vbase_vtbl_entries (binfo, &vid);
-  
+
   /* Clear BINFO_VTABLE_PATH_MARKED; it's set by
      build_vbase_offset_vtbl_entries.  */
   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
@@ -7277,7 +7261,7 @@ build_vtbl_initializer (tree binfo,
       tree vcall_index;
       tree fn, fn_original;
       tree init = NULL_TREE;
-      
+
       fn = BV_FN (v);
       fn_original = fn;
       if (DECL_THUNK_P (fn))
@@ -7291,7 +7275,7 @@ build_vtbl_initializer (tree binfo,
            }
          fn_original = THUNK_TARGET (fn);
        }
-      
+
       /* If the only definition of this function signature along our
         primary base chain is from a lost primary, this vtable slot will
         never be used, so just zero it out.  This is important to avoid
@@ -7330,16 +7314,24 @@ build_vtbl_initializer (tree binfo,
          /* You can't call an abstract virtual function; it's abstract.
             So, we replace these functions with __pure_virtual.  */
          if (DECL_PURE_VIRTUAL_P (fn_original))
-           fn = abort_fndecl;
-         else if (!integer_zerop (delta) || vcall_index)
            {
-             fn = make_thunk (fn, /*this_adjusting=*/1, delta, vcall_index);
-             if (!DECL_NAME (fn))
-               finish_thunk (fn);
+             fn = abort_fndecl;
+             if (abort_fndecl_addr == NULL)
+               abort_fndecl_addr = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
+             init = abort_fndecl_addr;
+           }
+         else
+           {
+             if (!integer_zerop (delta) || vcall_index)
+               {
+                 fn = make_thunk (fn, /*this_adjusting=*/1, delta, vcall_index);
+                 if (!DECL_NAME (fn))
+                   finish_thunk (fn);
+               }
+             /* Take the address of the function, considering it to be of an
+                appropriate generic type.  */
+             init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
            }
-         /* Take the address of the function, considering it to be of an
-            appropriate generic type.  */
-         init = build1 (ADDR_EXPR, vfunc_ptr_type_node, fn);
        }
 
       /* And add it to the chain of initializers.  */
@@ -7362,13 +7354,13 @@ build_vtbl_initializer (tree binfo,
              }
        }
       else
-        vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
+       vfun_inits = tree_cons (NULL_TREE, init, vfun_inits);
     }
 
   /* The initializers for virtual functions were built up in reverse
      order; straighten them out now.  */
   vfun_inits = nreverse (vfun_inits);
-  
+
   /* The negative offset initializers are also in reverse order.  */
   vid.inits = nreverse (vid.inits);
 
@@ -7410,11 +7402,11 @@ build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
 
   /* If there are no virtual baseclasses, then there is nothing to
      do.  */
-  if (!TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo)))
+  if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
     return;
 
   t = vid->derived;
-  
+
   /* We might be a primary base class.  Go up the inheritance hierarchy
      until we find the most derived class of which we are a primary base:
      it is the offset of that which we need to use.  */
@@ -7446,7 +7438,7 @@ build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
     {
       tree b;
       tree delta;
-      
+
       if (!BINFO_VIRTUAL_P (vbase))
        continue;
 
@@ -7461,7 +7453,7 @@ build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
       BINFO_VTABLE_PATH_MARKED (b) = 1;
 
       /* Figure out where we can find this vbase offset.  */
-      delta = size_binop (MULT_EXPR, 
+      delta = size_binop (MULT_EXPR,
                          vid->index,
                          convert (ssizetype,
                                   TYPE_SIZE_UNIT (vtable_entry_type)));
@@ -7481,12 +7473,12 @@ build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
         we are walking in inheritance graph order so these end up in
         the right order.  */
       delta = size_diffop (BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
-      
-      *vid->last_init 
+
+      *vid->last_init
        = build_tree_list (NULL_TREE,
-                          fold (build1 (NOP_EXPR, 
-                                        vtable_entry_type,
-                                        delta)));
+                          fold_build1 (NOP_EXPR,
+                                       vtable_entry_type,
+                                       delta));
       vid->last_init = &TREE_CHAIN (*vid->last_init);
     }
 }
@@ -7546,7 +7538,7 @@ add_vcall_offset_vtbl_entries_r (tree binfo, vtbl_init_data* vid)
      through the recursion in build_vcall_and_vbase_vtbl_entries.  */
   if (BINFO_VIRTUAL_P (binfo) && vid->vbase != binfo)
     return;
-  
+
   /* If BINFO has a primary base, process it first.  */
   primary_binfo = get_primary_binfo (binfo);
   if (primary_binfo)
@@ -7604,8 +7596,7 @@ add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
             might be a lost primary, so just skip down to vid->binfo.  */
          if (BINFO_VIRTUAL_P (non_primary_binfo))
            {
-             if (non_primary_binfo != vid->vbase)
-               abort ();
+             gcc_assert (non_primary_binfo == vid->vbase);
              non_primary_binfo = vid->binfo;
              break;
            }
@@ -7621,7 +7612,7 @@ add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
           where rtti_binfo is the most derived type.  */
        non_primary_binfo
          = original_binfo (non_primary_binfo, vid->rtti_binfo);
-      
+
       for (base_virtuals = BINFO_VIRTUALS (binfo),
             derived_virtuals = BINFO_VIRTUALS (non_primary_binfo),
             orig_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
@@ -7639,7 +7630,7 @@ add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
          /* When processing BINFO, we only want to generate vcall slots for
             function slots introduced in BINFO.  So don't try to generate
             one if the function isn't even defined in BINFO.  */
-         if (!same_type_p (DECL_CONTEXT (orig_fn), BINFO_TYPE (binfo)))
+         if (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), DECL_CONTEXT (orig_fn)))
            continue;
 
          add_vcall_offset (orig_fn, binfo, vid);
@@ -7654,16 +7645,14 @@ add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
 {
   size_t i;
   tree vcall_offset;
+  tree derived_entry;
 
   /* If there is already an entry for a function with the same
      signature as FN, then we do not need a second vcall offset.
      Check the list of functions already present in the derived
      class vtable.  */
-  for (i = 0; i < VARRAY_ACTIVE_SIZE (vid->fns); ++i) 
+  for (i = 0; VEC_iterate (tree, vid->fns, i, derived_entry); ++i)
     {
-      tree derived_entry;
-
-      derived_entry = VARRAY_TREE (vid->fns, i);
       if (same_signature_p (derived_entry, orig_fn)
          /* We only use one vcall offset for virtual destructors,
             even though there are two virtual table entries.  */
@@ -7677,20 +7666,20 @@ add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
      offset.  */
   if (vid->binfo == TYPE_BINFO (vid->derived))
     {
-      tree_pair_p elt = VEC_safe_push (tree_pair_s,
+      tree_pair_p elt = VEC_safe_push (tree_pair_s, gc,
                                       CLASSTYPE_VCALL_INDICES (vid->derived),
                                       NULL);
       elt->purpose = orig_fn;
       elt->value = vid->index;
     }
-  
+
   /* The next vcall offset will be found at a more negative
      offset.  */
   vid->index = size_binop (MINUS_EXPR, vid->index,
                           ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
 
   /* Keep track of this function.  */
-  VARRAY_PUSH_TREE (vid->fns, orig_fn);
+  VEC_safe_push (tree, gc, vid->fns, orig_fn);
 
   if (vid->generate_vcall_entries)
     {
@@ -7712,8 +7701,8 @@ add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
             BINFO_OFFSET from vid->binfo.  */
          vcall_offset = size_diffop (BINFO_OFFSET (base),
                                      BINFO_OFFSET (vid->binfo));
-         vcall_offset = fold (build1 (NOP_EXPR, vtable_entry_type,
-                                      vcall_offset));
+         vcall_offset = fold_build1 (NOP_EXPR, vtable_entry_type,
+                                     vcall_offset);
        }
       /* Add the initializer to the vtable.  */
       *vid->last_init = build_tree_list (NULL_TREE, vcall_offset);
@@ -7742,7 +7731,7 @@ build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
      primary base, and then add the offset in the vtbl to that value.  */
   b = binfo;
   while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
-         && !BINFO_LOST_PRIMARY_P (b))
+        && !BINFO_LOST_PRIMARY_P (b))
     {
       tree primary_base;
 
@@ -7758,15 +7747,15 @@ build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
     decl = build_address (get_tinfo_decl (t));
   else
     decl = integer_zero_node;
-  
+
   /* Convert the declaration to a type that can be stored in the
      vtable.  */
   init = build_nop (vfunc_ptr_type_node, decl);
   *vid->last_init = build_tree_list (NULL_TREE, init);
   vid->last_init = &TREE_CHAIN (*vid->last_init);
 
-  /* Add the offset-to-top entry.  It comes earlier in the vtable that
-     the the typeinfo entry.  Convert the offset to look like a
+  /* Add the offset-to-top entry.  It comes earlier in the vtable than
+     the typeinfo entry.  Convert the offset to look like a
      function pointer, so that we can put it in the vtable.  */
   init = build_nop (vfunc_ptr_type_node, offset);
   *vid->last_init = build_tree_list (NULL_TREE, init);
@@ -7794,10 +7783,13 @@ cp_fold_obj_type_ref (tree ref, tree known_type)
   fndecl = BV_FN (v);
 
 #ifdef ENABLE_CHECKING
-  if (!tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref), DECL_VINDEX (fndecl)))
-    abort ();
+  gcc_assert (tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref),
+                                 DECL_VINDEX (fndecl)));
 #endif
 
+  cgraph_node (fndecl)->local.vtable_method = true;
+
   return build_address (fndecl);
 }
 
+#include "gt-cp-class.h"