OSDN Git Service

* cp-tree.h (commonparms): Remove prototype.
[pf3gnuchains/gcc-fork.git] / gcc / cp / tree.c
index 1e470eb..0a0b3ec 100644 (file)
@@ -1,6 +1,6 @@
 /* Language-dependent node constructors for parse phase of GNU compiler.
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -42,9 +42,6 @@ static int list_hash_eq (const void *, const void *);
 static hashval_t list_hash_pieces (tree, tree, tree);
 static hashval_t list_hash (const void *);
 static cp_lvalue_kind lvalue_p_1 (tree, int);
-static tree no_linkage_helper (tree *, int *, void *);
-static tree mark_local_for_remap_r (tree *, int *, void *);
-static tree cp_unsave_r (tree *, int *, void *);
 static tree build_target_expr (tree, tree);
 static tree count_trees_r (tree *, int *, void *);
 static tree verify_stmt_tree_r (tree *, int *, void *);
@@ -60,7 +57,7 @@ static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
    nonzero, rvalues of class type are considered lvalues.  */
 
 static cp_lvalue_kind
-lvalue_p_1 (tree ref, 
+lvalue_p_1 (tree ref,
             int treat_class_rvalues_as_lvalues)
 {
   cp_lvalue_kind op1_lvalue_kind = clk_none;
@@ -79,7 +76,6 @@ lvalue_p_1 (tree ref,
     case PREINCREMENT_EXPR:
     case PREDECREMENT_EXPR:
     case SAVE_EXPR:
-    case UNSAVE_EXPR:
     case TRY_CATCH_EXPR:
     case WITH_CLEANUP_EXPR:
     case REALPART_EXPR:
@@ -90,8 +86,12 @@ lvalue_p_1 (tree ref,
     case COMPONENT_REF:
       op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
                                    treat_class_rvalues_as_lvalues);
-      if (!op1_lvalue_kind 
-         /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some  
+      /* In an expression of the form "X.Y", the packed-ness of the
+        expression does not depend on "X".  */
+      op1_lvalue_kind &= ~clk_packed;
+      /* Look at the member designator.  */
+      if (!op1_lvalue_kind
+         /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
             situations.  */
          || TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
        ;
@@ -105,7 +105,7 @@ lvalue_p_1 (tree ref,
        }
       else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
        op1_lvalue_kind |= clk_packed;
-      
+
       return op1_lvalue_kind;
 
     case STRING_CST:
@@ -126,9 +126,13 @@ lvalue_p_1 (tree ref,
 
       /* A currently unresolved scope ref.  */
     case SCOPE_REF:
-      abort ();
+      gcc_unreachable ();
     case MAX_EXPR:
     case MIN_EXPR:
+      /* Disallow <? and >? as lvalues if either argument side-effects.  */
+      if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
+         || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
+       return clk_none;
       op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0),
                                    treat_class_rvalues_as_lvalues);
       op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
@@ -160,7 +164,7 @@ lvalue_p_1 (tree ref,
     case FUNCTION_DECL:
       /* All functions (except non-static-member functions) are
         lvalues.  */
-      return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) 
+      return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
              ? clk_none : clk_ordinary);
 
     case NON_DEPENDENT_EXPR:
@@ -197,7 +201,7 @@ lvalue_p_1 (tree ref,
 cp_lvalue_kind
 real_lvalue_p (tree ref)
 {
-  return lvalue_p_1 (ref, 
+  return lvalue_p_1 (ref,
                     /*treat_class_rvalues_as_lvalues=*/0);
 }
 
@@ -207,24 +211,10 @@ real_lvalue_p (tree ref)
 int
 lvalue_p (tree ref)
 {
-  return 
+  return
     (lvalue_p_1 (ref, /*class rvalue ok*/ 1) != clk_none);
 }
 
-/* Return nonzero if REF is an lvalue valid for this language;
-   otherwise, print an error message and return zero.  */
-
-int
-lvalue_or_else (tree ref, const char* string)
-{
-  if (!lvalue_p (ref))
-    {
-      error ("non-lvalue in %s", string);
-      return 0;
-    }
-  return 1;
-}
-
 /* Build a TARGET_EXPR, initializing the DECL with the VALUE.  */
 
 static tree
@@ -232,8 +222,8 @@ build_target_expr (tree decl, tree value)
 {
   tree t;
 
-  t = build (TARGET_EXPR, TREE_TYPE (decl), decl, value, 
-            cxx_maybe_build_cleanup (decl), NULL_TREE);
+  t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value,
+             cxx_maybe_build_cleanup (decl), NULL_TREE);
   /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
      ignore the TARGET_EXPR.  If there really turn out to be no
      side-effects, then the optimizer should be able to get rid of
@@ -251,6 +241,7 @@ build_local_temp (tree type)
 {
   tree slot = build_decl (VAR_DECL, NULL_TREE, type);
   DECL_ARTIFICIAL (slot) = 1;
+  DECL_IGNORED_P (slot) = 1;
   DECL_CONTEXT (slot) = current_function_decl;
   layout_decl (slot, 0);
   return slot;
@@ -298,7 +289,8 @@ build_cplus_new (tree type, tree init)
      type, don't mess with AGGR_INIT_EXPR.  */
   if (is_ctor || TREE_ADDRESSABLE (type))
     {
-      rval = build (AGGR_INIT_EXPR, type, fn, TREE_OPERAND (init, 1), slot);
+      rval = build3 (AGGR_INIT_EXPR, void_type_node, fn,
+                    TREE_OPERAND (init, 1), slot);
       TREE_SIDE_EFFECTS (rval) = 1;
       AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
     }
@@ -318,7 +310,7 @@ build_target_expr_with_type (tree init, tree type)
 {
   tree slot;
 
-  my_friendly_assert (!VOID_TYPE_P (type), 20040130);
+  gcc_assert (!VOID_TYPE_P (type));
 
   if (TREE_CODE (init) == TARGET_EXPR)
     return init;
@@ -346,7 +338,7 @@ force_target_expr (tree type, tree init)
 {
   tree slot;
 
-  my_friendly_assert (!VOID_TYPE_P (type), 20040130);
+  gcc_assert (!VOID_TYPE_P (type));
 
   slot = build_local_temp (type);
   return build_target_expr (slot, init);
@@ -382,9 +374,9 @@ build_cplus_array_type_1 (tree elt_type, tree index_type)
 
   /* Push these needs up so that initialization takes place
      more easily.  */
-  TYPE_NEEDS_CONSTRUCTING (t) 
+  TYPE_NEEDS_CONSTRUCTING (t)
     = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
-  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) 
+  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
     = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
   return t;
 }
@@ -409,7 +401,7 @@ build_cplus_array_type (tree elt_type, tree index_type)
 /* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
    arrays correctly.  In particular, if TYPE is an array of T's, and
    TYPE_QUALS is non-empty, returns an array of qualified T's.
-  
+
    FLAGS determines how to deal with illformed qualifications. If
    tf_ignore_bad_quals is set, then bad qualifications are dropped
    (this is permitted if TYPE was introduced via a typedef or template
@@ -425,10 +417,10 @@ build_cplus_array_type (tree elt_type, tree index_type)
    DR 295 queries this and the proposed resolution brings it into line
    with qualifying a reference.  We implement the DR.  We also behave
    in a similar manner for restricting non-pointer types.  */
+
 tree
-cp_build_qualified_type_real (tree type, 
-                              int type_quals, 
+cp_build_qualified_type_real (tree type,
+                              int type_quals,
                               tsubst_flags_t complain)
 {
   tree result;
@@ -445,8 +437,8 @@ cp_build_qualified_type_real (tree type,
       /* In C++, the qualification really applies to the array element
         type.  Obtain the appropriately qualified element type.  */
       tree t;
-      tree element_type 
-       = cp_build_qualified_type_real (TREE_TYPE (type), 
+      tree element_type
+       = cp_build_qualified_type_real (TREE_TYPE (type),
                                        type_quals,
                                        complain);
 
@@ -455,29 +447,29 @@ cp_build_qualified_type_real (tree type,
 
       /* See if we already have an identically qualified type.  */
       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
-       if (cp_type_quals (t) == type_quals 
+       if (cp_type_quals (t) == type_quals
            && TYPE_NAME (t) == TYPE_NAME (type)
            && TYPE_CONTEXT (t) == TYPE_CONTEXT (type))
          break;
-         
+
       if (!t)
        {
          /* Make a new array type, just like the old one, but with the
             appropriately qualified element type.  */
-         t = build_type_copy (type);
+         t = build_variant_type_copy (type);
          TREE_TYPE (t) = element_type;
        }
 
       /* Even if we already had this variant, we update
         TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
-        they changed since the variant was originally created.  
-        
+        they changed since the variant was originally created.
+
         This seems hokey; if there is some way to use a previous
         variant *without* coming through here,
         TYPE_NEEDS_CONSTRUCTING will never be updated.  */
-      TYPE_NEEDS_CONSTRUCTING (t) 
+      TYPE_NEEDS_CONSTRUCTING (t)
        = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
-      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) 
+      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
        = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
       return t;
     }
@@ -493,7 +485,7 @@ cp_build_qualified_type_real (tree type,
       t = cp_build_qualified_type_real (t, type_quals, complain);
       return build_ptrmemfunc_type (t);
     }
-  
+
   /* A reference, function or method type shall not be cv qualified.
      [dcl.ref], [dct.fct]  */
   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
@@ -504,7 +496,7 @@ cp_build_qualified_type_real (tree type,
       bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
       type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
     }
-  
+
   /* A restrict-qualified type must be a pointer (or reference)
      to object or incomplete type.  */
   if ((type_quals & TYPE_QUAL_RESTRICT)
@@ -529,13 +521,13 @@ cp_build_qualified_type_real (tree type,
       if (bad_quals)
        {
          tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
+
          if (!(complain & tf_ignore_bad_quals))
-           error ("`%V' qualifiers cannot be applied to `%T'",
+           error ("%qV qualifiers cannot be applied to %qT",
                   bad_type, type);
        }
     }
-  
+
   /* Retrieve (or create) the appropriately qualified variant.  */
   result = build_qualified_type (type, type_quals);
 
@@ -543,7 +535,7 @@ cp_build_qualified_type_real (tree type,
      then we need to unshare the record that holds the cached
      pointer-to-member-function type, because these will be distinct
      between the unqualified and qualified types.  */
-  if (result != type 
+  if (result != type
       && TREE_CODE (type) == POINTER_TYPE
       && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
     TYPE_LANG_SPECIFIC (result) = NULL;
@@ -562,82 +554,87 @@ canonical_type_variant (tree t)
   return cp_build_qualified_type (TYPE_MAIN_VARIANT (t), cp_type_quals (t));
 }
 \f
-/* Makes new binfos for the indirect bases under BINFO. T is the most
-   derived TYPE. PREV is the previous binfo, whose TREE_CHAIN we make
-   point to this binfo. We return the last BINFO created.
-
-   The CLASSTYPE_VBASECLASSES list of T is constructed in reverse
-   order (pre-order, depth-first, right-to-left). You must nreverse it.
+/* Makes a copy of BINFO and TYPE, which is to be inherited into a
+   graph dominated by T.  If BINFO is NULL, TYPE is a dependent base,
+   and we do a shallow copy.  If BINFO is non-NULL, we do a deep copy.
+   VIRT indicates whether TYPE is inherited virtually or not.
+   IGO_PREV points at the previous binfo of the inheritance graph
+   order chain.  The newly copied binfo's TREE_CHAIN forms this
+   ordering.
+
+   The CLASSTYPE_VBASECLASSES vector of T is constructed in the
+   correct order. That is in the order the bases themselves should be
+   constructed in.
 
    The BINFO_INHERITANCE of a virtual base class points to the binfo
-   og the most derived type.
-
-   The binfo's TREE_CHAIN is set to inheritance graph order, but bases
-   for non-class types are not included (i.e. those which are
-   dependent bases in non-instantiated templates).  */
+   of the most derived type. ??? We could probably change this so that
+   BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
+   remove a field.  They currently can only differ for primary virtual
+   virtual bases.  */
 
 tree
-copy_base_binfos (tree binfo, tree t, tree prev)
-{
-  tree binfos = BINFO_BASETYPES (binfo);
-  int n, ix;
-
-  if (prev)
-    TREE_CHAIN (prev) = binfo;
-  prev = binfo;
-  
-  if (binfos == NULL_TREE)
-    return prev;
-
-  n = TREE_VEC_LENGTH (binfos);
-  
-  /* Now copy the structure beneath BINFO.  */
-  for (ix = 0; ix != n; ix++)
+copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
+{
+  tree new_binfo;
+
+  if (virt)
+    {
+      /* See if we've already made this virtual base.  */
+      new_binfo = binfo_for_vbase (type, t);
+      if (new_binfo)
+       return new_binfo;
+    }
+
+  new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
+  BINFO_TYPE (new_binfo) = type;
+
+  /* Chain it into the inheritance graph.  */
+  TREE_CHAIN (*igo_prev) = new_binfo;
+  *igo_prev = new_binfo;
+
+  if (binfo)
     {
-      tree base_binfo = TREE_VEC_ELT (binfos, ix);
-      tree new_binfo = NULL_TREE;
+      int ix;
+      tree base_binfo;
 
-      if (!CLASS_TYPE_P (BINFO_TYPE (base_binfo)))
-       {
-         my_friendly_assert (binfo == TYPE_BINFO (t), 20030204);
-         
-         new_binfo = base_binfo;
-         TREE_CHAIN (prev) = new_binfo;
-         prev = new_binfo;
-         BINFO_INHERITANCE_CHAIN (new_binfo) = binfo;
-         BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
-       }
-      else if (TREE_VIA_VIRTUAL (base_binfo))
-       {
-         new_binfo = purpose_member (BINFO_TYPE (base_binfo),
-                                     CLASSTYPE_VBASECLASSES (t));
-         if (new_binfo)
-           new_binfo = TREE_VALUE (new_binfo);
-       }
-      
-      if (!new_binfo)
+      gcc_assert (!BINFO_DEPENDENT_BASE_P (binfo));
+      gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
+
+      BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
+      BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
+
+      /* We do not need to copy the accesses, as they are read only.  */
+      BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
+
+      /* Recursively copy base binfos of BINFO.  */
+      for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
        {
-         new_binfo = make_binfo (BINFO_OFFSET (base_binfo),
-                                 base_binfo, NULL_TREE,
-                                 BINFO_VIRTUALS (base_binfo));
-         prev = copy_base_binfos (new_binfo, t, prev);
-         if (TREE_VIA_VIRTUAL (base_binfo))
-           {
-             CLASSTYPE_VBASECLASSES (t)
-               = tree_cons (BINFO_TYPE (new_binfo), new_binfo,
-                            CLASSTYPE_VBASECLASSES (t));
-             TREE_VIA_VIRTUAL (new_binfo) = 1;
-             BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
-           }
-         else
-           BINFO_INHERITANCE_CHAIN (new_binfo) = binfo;
+         tree new_base_binfo;
+
+         gcc_assert (!BINFO_DEPENDENT_BASE_P (base_binfo));
+         new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
+                                      t, igo_prev,
+                                      BINFO_VIRTUAL_P (base_binfo));
+
+         if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
+           BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
+         BINFO_BASE_APPEND (new_binfo, new_base_binfo);
        }
-      TREE_VEC_ELT (binfos, ix) = new_binfo;
     }
+  else
+    BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
 
-  return prev;
-}
+  if (virt)
+    {
+      /* Push it onto the list after any virtual bases it contains
+        will have been pushed.  */
+      VEC_quick_push (tree, CLASSTYPE_VBASECLASSES (t), new_binfo);
+      BINFO_VIRTUAL_P (new_binfo) = 1;
+      BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
+    }
 
+  return new_binfo;
+}
 \f
 /* Hashing of lists so that we don't make duplicates.
    The entry point is `list_hash_canon'.  */
@@ -650,7 +647,7 @@ copy_base_binfos (tree binfo, tree t, tree prev)
 
 static GTY ((param_is (union tree_node))) htab_t list_hash_table;
 
-struct list_proxy 
+struct list_proxy
 {
   tree purpose;
   tree value;
@@ -679,10 +676,10 @@ static hashval_t
 list_hash_pieces (tree purpose, tree value, tree chain)
 {
   hashval_t hashcode = 0;
-  
+
   if (chain)
     hashcode += TREE_HASH (chain);
-  
+
   if (value)
     hashcode += TREE_HASH (value);
   else
@@ -700,8 +697,8 @@ static hashval_t
 list_hash (const void* p)
 {
   tree t = (tree) p;
-  return list_hash_pieces (TREE_PURPOSE (t), 
-                          TREE_VALUE (t), 
+  return list_hash_pieces (TREE_PURPOSE (t),
+                          TREE_VALUE (t),
                           TREE_CHAIN (t));
 }
 
@@ -739,70 +736,7 @@ hash_tree_chain (tree value, tree chain)
 {
   return hash_tree_cons (NULL_TREE, value, chain);
 }
-
-/* Similar, but used for concatenating two lists.  */
-
-tree
-hash_chainon (tree list1, tree list2)
-{
-  if (list2 == 0)
-    return list1;
-  if (list1 == 0)
-    return list2;
-  if (TREE_CHAIN (list1) == NULL_TREE)
-    return hash_tree_chain (TREE_VALUE (list1), list2);
-  return hash_tree_chain (TREE_VALUE (list1),
-                         hash_chainon (TREE_CHAIN (list1), list2));
-}
 \f
-/* Build an association between TYPE and some parameters:
-
-   OFFSET is the offset added to `this' to convert it to a pointer
-   of type `TYPE *'
-
-   BINFO is the base binfo to use, if we are deriving from one.  This
-   is necessary, as we want specialized parent binfos from base
-   classes, so that the VTABLE_NAMEs of bases are for the most derived
-   type, instead of the simple type.
-
-   VTABLE is the virtual function table with which to initialize
-   sub-objects of type TYPE.
-
-   VIRTUALS are the virtual functions sitting in VTABLE.  */
-
-tree
-make_binfo (tree offset, tree binfo, tree vtable, tree virtuals)
-{
-  tree new_binfo = make_tree_vec (BINFO_LANG_ELTS);
-  tree type;
-
-  if (TREE_CODE (binfo) == TREE_VEC)
-    {
-      type = BINFO_TYPE (binfo);
-      BINFO_DEPENDENT_BASE_P (new_binfo) = BINFO_DEPENDENT_BASE_P (binfo);
-    }
-  else
-    {
-      type = binfo;
-      binfo = NULL_TREE;
-      BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
-    }
-
-  TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type);
-  BINFO_OFFSET (new_binfo) = offset;
-  BINFO_VTABLE (new_binfo) = vtable;
-  BINFO_VIRTUALS (new_binfo) = virtuals;
-
-  if (binfo && !BINFO_DEPENDENT_BASE_P (binfo)
-      && BINFO_BASETYPES (binfo) != NULL_TREE)
-    {
-      BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo));
-      /* We do not need to copy the accesses, as they are read only.  */
-      BINFO_BASEACCESSES (new_binfo) = BINFO_BASEACCESSES (binfo);
-    }
-  return new_binfo;
-}
-
 void
 debug_binfo (tree elem)
 {
@@ -835,23 +769,6 @@ debug_binfo (tree elem)
 }
 
 int
-count_functions (tree t)
-{
-  int i;
-  if (TREE_CODE (t) == FUNCTION_DECL)
-    return 1;
-  else if (TREE_CODE (t) == OVERLOAD)
-    {
-      for (i = 0; t; t = OVL_CHAIN (t))
-       i++;
-      return i;
-    }
-
-  abort ();
-  return 0;
-}
-
-int
 is_overloaded_fn (tree x)
 {
   /* A baselink is also considered an overloaded function.  */
@@ -867,13 +784,13 @@ is_overloaded_fn (tree x)
 
 int
 really_overloaded_fn (tree x)
-{     
+{
   /* A baselink is also considered an overloaded function.  */
   if (TREE_CODE (x) == OFFSET_REF)
     x = TREE_OPERAND (x, 1);
   if (BASELINK_P (x))
     x = BASELINK_FUNCTIONS (x);
-  
+
   return ((TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x))
          || DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
          || TREE_CODE (x) == TEMPLATE_ID_EXPR);
@@ -882,23 +799,13 @@ really_overloaded_fn (tree x)
 tree
 get_first_fn (tree from)
 {
-  my_friendly_assert (is_overloaded_fn (from), 9);
+  gcc_assert (is_overloaded_fn (from));
   /* A baselink is also considered an overloaded function.  */
   if (BASELINK_P (from))
     from = BASELINK_FUNCTIONS (from);
   return OVL_CURRENT (from);
 }
 
-/* Returns nonzero if T is a ->* or .* expression that refers to a
-   member function.  */
-
-int
-bound_pmf_p (tree t)
-{
-  return (TREE_CODE (t) == OFFSET_REF
-         && TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (t, 1))));
-}
-
 /* Return a new OVL node, concatenating it with the old one.  */
 
 tree
@@ -908,7 +815,7 @@ ovl_cons (tree decl, tree chain)
   TREE_TYPE (result) = unknown_type_node;
   OVL_FUNCTION (result) = decl;
   TREE_CHAIN (result) = chain;
-  
+
   return result;
 }
 
@@ -957,8 +864,7 @@ cxx_printable_name (tree decl, int v)
        ring_counter += 1;
       if (ring_counter == PRINT_RING_SIZE)
        ring_counter = 0;
-      if (decl_ring[ring_counter] == current_function_decl)
-       abort ();
+      gcc_assert (decl_ring[ring_counter] != current_function_decl);
     }
 
   if (print_ring[ring_counter])
@@ -984,7 +890,7 @@ build_exception_variant (tree type, tree raises)
       return v;
 
   /* Need to build a new variant.  */
-  v = build_type_copy (type);
+  v = build_variant_type_copy (type);
   TYPE_RAISES_EXCEPTIONS (v) = raises;
   return v;
 }
@@ -1007,7 +913,7 @@ bind_template_template_parm (tree t, tree newargs)
   TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
   TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
   TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
-    = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), 
+    = tree_cons (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t),
                 newargs, NULL_TREE);
 
   TREE_TYPE (decl) = t2;
@@ -1021,11 +927,13 @@ bind_template_template_parm (tree t, tree newargs)
 /* Called from count_trees via walk_tree.  */
 
 static tree
-count_trees_r (tree* tp ATTRIBUTE_UNUSED , 
-               int* walk_subtrees ATTRIBUTE_UNUSED , 
-               void* data)
+count_trees_r (tree *tp, int *walk_subtrees, void *data)
 {
-  ++ *((int*) data);
+  ++*((int *) data);
+
+  if (TYPE_P (*tp))
+    *walk_subtrees = 0;
+
   return NULL_TREE;
 }
 
@@ -1038,13 +946,13 @@ count_trees (tree t)
   int n_trees = 0;
   walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
   return n_trees;
-}  
+}
 
 /* Called from verify_stmt_tree via walk_tree.  */
 
 static tree
-verify_stmt_tree_r (tree* tp, 
-                    int* walk_subtrees ATTRIBUTE_UNUSED , 
+verify_stmt_tree_r (tree* tp,
+                    int* walk_subtrees ATTRIBUTE_UNUSED ,
                     void* data)
 {
   tree t = *tp;
@@ -1056,9 +964,8 @@ verify_stmt_tree_r (tree* tp,
 
   /* If this statement is already present in the hash table, then
      there is a circularity in the statement tree.  */
-  if (htab_find (*statements, t))
-    abort ();
-  
+  gcc_assert (!htab_find (*statements, t));
+
   slot = htab_find_slot (*statements, t, INSERT);
   *slot = t;
 
@@ -1081,8 +988,8 @@ verify_stmt_tree (tree t)
 /* Called from find_tree via walk_tree.  */
 
 static tree
-find_tree_r (tree* tp, 
-             int* walk_subtrees ATTRIBUTE_UNUSED , 
+find_tree_r (tree* tp,
+             int* walk_subtrees ATTRIBUTE_UNUSED ,
              void* data)
 {
   if (*tp == (tree) data)
@@ -1099,38 +1006,75 @@ find_tree (tree t, tree x)
   return walk_tree_without_duplicates (&t, find_tree_r, x);
 }
 
-/* Passed to walk_tree.  Checks for the use of types with no linkage.  */
-
-static tree
-no_linkage_helper (tree* tp, 
-                   int* walk_subtrees ATTRIBUTE_UNUSED , 
-                   void* data ATTRIBUTE_UNUSED )
-{
-  tree t = *tp;
-
-  if (TYPE_P (t)
-      && (CLASS_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE)
-      && (decl_function_context (TYPE_MAIN_DECL (t))
-         || TYPE_ANONYMOUS_P (t)))
-    return t;
-  return NULL_TREE;
-}
-
 /* Check if the type T depends on a type with no linkage and if so, return
-   it.  */
+   it.  If RELAXED_P then do not consider a class type declared within
+   a TREE_PUBLIC function to have no linkage.  */
 
 tree
-no_linkage_check (tree t)
+no_linkage_check (tree t, bool relaxed_p)
 {
+  tree r;
+
   /* There's no point in checking linkage on template functions; we
      can't know their complete types.  */
   if (processing_template_decl)
     return NULL_TREE;
 
-  t = walk_tree_without_duplicates (&t, no_linkage_helper, NULL);
-  if (t != error_mark_node)
-    return t;
-  return NULL_TREE;
+  switch (TREE_CODE (t))
+    {
+      tree fn;
+
+    case RECORD_TYPE:
+      if (TYPE_PTRMEMFUNC_P (t))
+       goto ptrmem;
+      /* Fall through.  */
+    case UNION_TYPE:
+      if (!CLASS_TYPE_P (t))
+       return NULL_TREE;
+      /* Fall through.  */
+    case ENUMERAL_TYPE:
+      if (TYPE_ANONYMOUS_P (t))
+       return t;
+      fn = decl_function_context (TYPE_MAIN_DECL (t));
+      if (fn && (!relaxed_p || !TREE_PUBLIC (fn)))
+       return t;
+      return NULL_TREE;
+
+    case ARRAY_TYPE:
+    case POINTER_TYPE:
+    case REFERENCE_TYPE:
+      return no_linkage_check (TREE_TYPE (t), relaxed_p);
+
+    case OFFSET_TYPE:
+    ptrmem:
+      r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
+                           relaxed_p);
+      if (r)
+       return r;
+      return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
+
+    case METHOD_TYPE:
+      r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p);
+      if (r)
+       return r;
+      /* Fall through.  */
+    case FUNCTION_TYPE:
+      {
+       tree parm;
+       for (parm = TYPE_ARG_TYPES (t);
+            parm && parm != void_list_node;
+            parm = TREE_CHAIN (parm))
+         {
+           r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
+           if (r)
+             return r;
+         }
+       return no_linkage_check (TREE_TYPE (t), relaxed_p);
+      }
+
+    default:
+      return NULL_TREE;
+    }
 }
 
 #ifdef GATHER_STATISTICS
@@ -1155,9 +1099,9 @@ cxx_print_statistics (void)
 tree
 array_type_nelts_top (tree type)
 {
-  return fold (build (PLUS_EXPR, sizetype,
-                     array_type_nelts (type),
-                     integer_one_node));
+  return fold (build2 (PLUS_EXPR, sizetype,
+                      array_type_nelts (type),
+                      integer_one_node));
 }
 
 /* Return, as an INTEGER_CST node, the number of elements for TYPE
@@ -1172,7 +1116,7 @@ array_type_nelts_total (tree type)
   while (TREE_CODE (type) == ARRAY_TYPE)
     {
       tree n = array_type_nelts_top (type);
-      sz = fold (build (MULT_EXPR, sizetype, sz, n));
+      sz = fold (build2 (MULT_EXPR, sizetype, sz, n));
       type = TREE_TYPE (type);
     }
   return sz;
@@ -1204,15 +1148,15 @@ bot_manip (tree* tp, int* walk_subtrees, void* data)
          u = build_cplus_new
            (TREE_TYPE (t), break_out_target_exprs (TREE_OPERAND (t, 1)));
        }
-      else 
+      else
        {
          u = build_target_expr_with_type
            (break_out_target_exprs (TREE_OPERAND (t, 1)), TREE_TYPE (t));
        }
 
       /* Map the old variable to the new one.  */
-      splay_tree_insert (target_remap, 
-                        (splay_tree_key) TREE_OPERAND (t, 0), 
+      splay_tree_insert (target_remap,
+                        (splay_tree_key) TREE_OPERAND (t, 0),
                         (splay_tree_value) TREE_OPERAND (u, 0));
 
       /* Replace the old expression with the new version.  */
@@ -1229,14 +1173,14 @@ bot_manip (tree* tp, int* walk_subtrees, void* data)
   /* Make a copy of this node.  */
   return copy_tree_r (tp, walk_subtrees, NULL);
 }
-  
+
 /* Replace all remapped VAR_DECLs in T with their new equivalents.
    DATA is really a splay-tree mapping old variables to new
    variables.  */
 
 static tree
-bot_replace (tree* t, 
-             int* walk_subtrees ATTRIBUTE_UNUSED , 
+bot_replace (tree* t,
+             int* walk_subtrees ATTRIBUTE_UNUSED ,
              void* data)
 {
   splay_tree target_remap = ((splay_tree) data);
@@ -1251,7 +1195,7 @@ bot_replace (tree* t,
 
   return NULL_TREE;
 }
-       
+
 /* When we parse a default argument expression, we may create
    temporary variables via TARGET_EXPRs.  When we actually use the
    default-argument expression, we make a copy of the expression, but
@@ -1264,8 +1208,8 @@ break_out_target_exprs (tree t)
   static splay_tree target_remap;
 
   if (!target_remap_count++)
-    target_remap = splay_tree_new (splay_tree_compare_pointers, 
-                                  /*splay_tree_delete_key_fn=*/NULL, 
+    target_remap = splay_tree_new (splay_tree_compare_pointers,
+                                  /*splay_tree_delete_key_fn=*/NULL,
                                   /*splay_tree_delete_value_fn=*/NULL);
   walk_tree (&t, bot_manip, target_remap, NULL);
   walk_tree (&t, bot_replace, target_remap, NULL);
@@ -1294,7 +1238,6 @@ build_min_nt (enum tree_code code, ...)
 
   t = make_node (code);
   length = TREE_CODE_LENGTH (code);
-  TREE_COMPLEXITY (t) = input_line;
 
   for (i = 0; i < length; i++)
     {
@@ -1321,7 +1264,6 @@ build_min (enum tree_code code, tree tt, ...)
   t = make_node (code);
   length = TREE_CODE_LENGTH (code);
   TREE_TYPE (t) = tt;
-  TREE_COMPLEXITY (t) = input_line;
 
   for (i = 0; i < length; i++)
     {
@@ -1352,7 +1294,6 @@ build_min_non_dep (enum tree_code code, tree non_dep, ...)
   t = make_node (code);
   length = TREE_CODE_LENGTH (code);
   TREE_TYPE (t) = TREE_TYPE (non_dep);
-  TREE_COMPLEXITY (t) = input_line;
   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
 
   for (i = 0; i < length; i++)
@@ -1365,30 +1306,11 @@ build_min_non_dep (enum tree_code code, tree non_dep, ...)
     /* This should not be considered a COMPOUND_EXPR, because it
        resolves to an overload.  */
     COMPOUND_EXPR_OVERLOADED (t) = 1;
-  
+
   va_end (p);
   return t;
 }
 
-/* Returns an INTEGER_CST (of type `int') corresponding to I.
-   Multiple calls with the same value of I may or may not yield the
-   same node; therefore, callers should never modify the node
-   returned.  */
-
-static GTY(()) tree shared_int_cache[256];
-
-tree
-build_shared_int_cst (int i)
-{
-  if (i >= 256)
-    return build_int_2 (i, 0);
-  
-  if (!shared_int_cache[i])
-    shared_int_cache[i] = build_int_2 (i, 0);
-  
-  return shared_int_cache[i];
-}
-
 tree
 get_type_decl (tree t)
 {
@@ -1396,29 +1318,8 @@ get_type_decl (tree t)
     return t;
   if (TYPE_P (t))
     return TYPE_STUB_DECL (t);
-  if (t == error_mark_node)
-    return t;
-  
-  abort ();
-
-  /* Stop compiler from complaining control reaches end of non-void function.  */
-  return 0;
-}
-
-/* Return first vector element whose BINFO_TYPE is ELEM.
-   Return 0 if ELEM is not in VEC.  VEC may be NULL_TREE.  */
-
-tree
-vec_binfo_member (tree elem, tree vec)
-{
-  int i;
-
-  if (vec)
-    for (i = 0; i < TREE_VEC_LENGTH (vec); ++i)
-      if (same_type_p (elem, BINFO_TYPE (TREE_VEC_ELT (vec, i))))
-       return TREE_VEC_ELT (vec, i);
-
-  return NULL_TREE;
+  gcc_assert (t == error_mark_node);
+  return t;
 }
 
 /* Returns the namespace that contains DECL, whether directly or
@@ -1465,7 +1366,7 @@ cp_tree_equal (tree t1, tree t2)
   /* They might have become equal now.  */
   if (t1 == t2)
     return true;
-  
+
   if (code1 != code2)
     return false;
 
@@ -1512,7 +1413,7 @@ cp_tree_equal (tree t1, tree t2)
       {
        tree o1 = TREE_OPERAND (t1, 0);
        tree o2 = TREE_OPERAND (t2, 0);
-       
+
        /* Special case: if either target is an unallocated VAR_DECL,
           it means that it's going to be unified with whatever the
           TARGET_EXPR is really supposed to initialize, so treat it
@@ -1525,10 +1426,10 @@ cp_tree_equal (tree t1, tree t2)
          /*Nop*/;
        else if (!cp_tree_equal (o1, o2))
          return false;
-      
+
        return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
       }
-      
+
     case WITH_CLEANUP_EXPR:
       if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
        return false;
@@ -1547,6 +1448,12 @@ cp_tree_equal (tree t1, tree t2)
     case IDENTIFIER_NODE:
       return false;
 
+    case BASELINK:
+      return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
+             && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
+             && cp_tree_equal (BASELINK_FUNCTIONS (t1),
+                               BASELINK_FUNCTIONS (t2)));
+
     case TEMPLATE_PARM_INDEX:
       return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
              && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
@@ -1557,7 +1464,7 @@ cp_tree_equal (tree t1, tree t2)
       {
        unsigned ix;
        tree vec1, vec2;
-       
+
        if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
          return false;
        vec1 = TREE_OPERAND (t1, 1);
@@ -1565,7 +1472,7 @@ cp_tree_equal (tree t1, tree t2)
 
        if (!vec1 || !vec2)
          return !vec1 && !vec2;
-       
+
        if (TREE_VEC_LENGTH (vec1) != TREE_VEC_LENGTH (vec2))
          return false;
 
@@ -1573,16 +1480,16 @@ cp_tree_equal (tree t1, tree t2)
          if (!cp_tree_equal (TREE_VEC_ELT (vec1, ix),
                              TREE_VEC_ELT (vec2, ix)))
            return false;
-       
+
        return true;
       }
-      
+
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
       {
        tree o1 = TREE_OPERAND (t1, 0);
        tree o2 = TREE_OPERAND (t2, 0);
-       
+
        if (TREE_CODE (o1) != TREE_CODE (o2))
          return false;
        if (TYPE_P (o1))
@@ -1590,7 +1497,7 @@ cp_tree_equal (tree t1, tree t2)
        else
          return cp_tree_equal (o1, o2);
       }
-      
+
     case PTRMEM_CST:
       /* Two pointer-to-members are the same if they point to the same
         field or function in the same class.  */
@@ -1599,33 +1506,39 @@ cp_tree_equal (tree t1, tree t2)
 
       return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
 
+    case OVERLOAD:
+      if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2))
+       return false;
+      return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2));
+
     default:
       break;
     }
 
   switch (TREE_CODE_CLASS (code1))
     {
-    case '1':
-    case '2':
-    case '<':
-    case 'e':
-    case 'r':
-    case 's':
+    case tcc_unary:
+    case tcc_binary:
+    case tcc_comparison:
+    case tcc_expression:
+    case tcc_reference:
+    case tcc_statement:
       {
        int i;
-       
+
        for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
          if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
            return false;
-       
+
        return true;
       }
-    
-    case 't':
+
+    case tcc_type:
       return same_type_p (t1, t2);
+    default:
+      gcc_unreachable ();
     }
-
-  my_friendly_assert (0, 20030617);
+  /* We can get here with --disable-checking.  */
   return false;
 }
 
@@ -1645,7 +1558,7 @@ tree
 error_type (tree arg)
 {
   tree type = TREE_TYPE (arg);
-  
+
   if (TREE_CODE (type) == ARRAY_TYPE)
     ;
   else if (TREE_CODE (type) == ERROR_MARK)
@@ -1698,10 +1611,10 @@ maybe_dummy_object (tree type, tree* binfop)
 {
   tree decl, context;
   tree binfo;
-  
+
   if (current_class_type
       && (binfo = lookup_base (current_class_type, type,
-                              ba_ignore | ba_quiet, NULL)))
+                              ba_unique | ba_quiet, NULL)))
     context = current_class_type;
   else
     {
@@ -1712,7 +1625,7 @@ maybe_dummy_object (tree type, tree* binfop)
 
   if (binfop)
     *binfop = binfo;
-  
+
   if (current_class_ref && context == current_class_type
       /* Kludge: Make sure that current_class_type is actually
          correct.  It might not be if we're in the middle of
@@ -1756,7 +1669,7 @@ pod_type_p (tree t)
     return 1; /* pointer to member */
 
   if (TREE_CODE (t) == VECTOR_TYPE)
-    return 1; /* vectors are (small) arrays if scalars */
+    return 1; /* vectors are (small) arrays of scalars */
 
   if (! CLASS_TYPE_P (t))
     return 0; /* other non-class type (reference or function) */
@@ -1801,23 +1714,23 @@ const struct attribute_spec cxx_attribute_table[] =
 /* Handle a "java_interface" attribute; arguments as in
    struct attribute_spec.handler.  */
 static tree
-handle_java_interface_attribute (tree* node, 
-                                 tree name, 
-                                 tree args ATTRIBUTE_UNUSED , 
-                                 int flags, 
+handle_java_interface_attribute (tree* node,
+                                 tree name,
+                                 tree args ATTRIBUTE_UNUSED ,
+                                 int flags,
                                  bool* no_add_attrs)
 {
   if (DECL_P (*node)
       || !CLASS_TYPE_P (*node)
       || !TYPE_FOR_JAVA (*node))
     {
-      error ("`%s' attribute can only be applied to Java class definitions",
-            IDENTIFIER_POINTER (name));
+      error ("%qE attribute can only be applied to Java class definitions",
+            name);
       *no_add_attrs = true;
       return NULL_TREE;
     }
   if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
-    *node = build_type_copy (*node);
+    *node = build_variant_type_copy (*node);
   TYPE_JAVA_INTERFACE (*node) = 1;
 
   return NULL_TREE;
@@ -1826,10 +1739,10 @@ handle_java_interface_attribute (tree* node,
 /* Handle a "com_interface" attribute; arguments as in
    struct attribute_spec.handler.  */
 static tree
-handle_com_interface_attribute (tree* node, 
-                                tree name, 
-                                tree args ATTRIBUTE_UNUSED , 
-                                int flags ATTRIBUTE_UNUSED , 
+handle_com_interface_attribute (tree* node,
+                                tree name,
+                                tree args ATTRIBUTE_UNUSED ,
+                                int flags ATTRIBUTE_UNUSED ,
                                 bool* no_add_attrs)
 {
   static int warned;
@@ -1840,14 +1753,13 @@ handle_com_interface_attribute (tree* node,
       || !CLASS_TYPE_P (*node)
       || *node != TYPE_MAIN_VARIANT (*node))
     {
-      warning ("`%s' attribute can only be applied to class definitions",
-              IDENTIFIER_POINTER (name));
+      warning ("%qE attribute can only be applied to class definitions", name);
       return NULL_TREE;
     }
 
   if (!warned++)
-    warning ("`%s' is obsolete; g++ vtables are now COM-compatible by default",
-            IDENTIFIER_POINTER (name));
+    warning ("%qE is obsolete; g++ vtables are now COM-compatible by default",
+            name);
 
   return NULL_TREE;
 }
@@ -1855,10 +1767,10 @@ handle_com_interface_attribute (tree* node,
 /* Handle an "init_priority" attribute; arguments as in
    struct attribute_spec.handler.  */
 static tree
-handle_init_priority_attribute (tree* node, 
-                                tree name, 
-                                tree args, 
-                                int flags ATTRIBUTE_UNUSED , 
+handle_init_priority_attribute (tree* node,
+                                tree name,
+                                tree args,
+                                int flags ATTRIBUTE_UNUSED ,
                                 bool* no_add_attrs)
 {
   tree initp_expr = TREE_VALUE (args);
@@ -1867,7 +1779,7 @@ handle_init_priority_attribute (tree* node,
   int pri;
 
   STRIP_NOPS (initp_expr);
-         
+
   if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
     {
       error ("requested init_priority is not an integer constant");
@@ -1876,7 +1788,7 @@ handle_init_priority_attribute (tree* node,
     }
 
   pri = TREE_INT_CST_LOW (initp_expr);
-       
+
   type = strip_array_types (type);
 
   if (decl == NULL_TREE
@@ -1889,10 +1801,10 @@ handle_init_priority_attribute (tree* node,
         first time control passes through that
         function. This is not precise enough to pin down an
         init_priority value, so don't allow it.  */
-      || current_function_decl) 
+      || current_function_decl)
     {
-      error ("can only use `%s' attribute on file-scope definitions of objects of class type",
-            IDENTIFIER_POINTER (name));
+      error ("can only use %qE attribute on file-scope definitions "
+             "of objects of class type", name);
       *no_add_attrs = true;
       return NULL_TREE;
     }
@@ -1908,7 +1820,7 @@ handle_init_priority_attribute (tree* node,
      language and runtime support implementations.*/
   if (pri <= MAX_RESERVED_INIT_PRIORITY)
     {
-      warning 
+      warning
        ("requested init_priority is reserved for internal use");
     }
 
@@ -1919,13 +1831,23 @@ handle_init_priority_attribute (tree* node,
     }
   else
     {
-      error ("`%s' attribute is not supported on this platform",
-            IDENTIFIER_POINTER (name));
+      error ("%qE attribute is not supported on this platform", name);
       *no_add_attrs = true;
       return NULL_TREE;
     }
 }
 
+/* Return a new TINST_LEVEL for DECL at location locus.  */
+tree
+make_tinst_level (tree decl, location_t locus)
+{
+  tree tinst_level = make_node (TINST_LEVEL);
+  TREE_CHAIN (tinst_level) = NULL_TREE;
+  TINST_DECL (tinst_level) = decl;
+  TINST_LOCATION (tinst_level) = locus;
+  return tinst_level;
+}
+
 /* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
    thing pointed to by the constant.  */
 
@@ -1948,7 +1870,7 @@ cp_build_type_attribute_variant (tree type, tree attributes)
 
   new_type = build_type_attribute_variant (type, attributes);
   if (TREE_CODE (new_type) == FUNCTION_TYPE
-      && (TYPE_RAISES_EXCEPTIONS (new_type) 
+      && (TYPE_RAISES_EXCEPTIONS (new_type)
          != TYPE_RAISES_EXCEPTIONS (type)))
     new_type = build_exception_variant (new_type,
                                        TYPE_RAISES_EXCEPTIONS (type));
@@ -1956,23 +1878,20 @@ cp_build_type_attribute_variant (tree type, tree attributes)
 }
 
 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
-   traversal.  Called from walk_tree().  */
+   traversal.  Called from walk_tree.  */
 
-tree 
-cp_walk_subtrees (tree* tp, 
-                  int* walk_subtrees_p, 
-                  walk_tree_fn func, 
-                  void* data, 
-                  void* htab)
+tree
+cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
+                 void *data, struct pointer_set_t *pset)
 {
   enum tree_code code = TREE_CODE (*tp);
   location_t save_locus;
   tree result;
-  
+
 #define WALK_SUBTREE(NODE)                             \
   do                                                   \
     {                                                  \
-      result = walk_tree (&(NODE), func, data, htab);  \
+      result = walk_tree (&(NODE), func, data, pset);  \
       if (result) goto out;                            \
     }                                                  \
   while (0)
@@ -1980,8 +1899,8 @@ cp_walk_subtrees (tree* tp,
   /* Set input_location here so we get the right instantiation context
      if we call instantiate_decl from inlinable_function_p.  */
   save_locus = input_location;
-  if (EXPR_LOCUS (*tp))
-    input_location = *EXPR_LOCUS (*tp);
+  if (EXPR_HAS_LOCATION (*tp))
+    input_location = EXPR_LOCATION (*tp);
 
   /* Not one of the easy cases.  We must explicitly go through the
      children.  */
@@ -2002,6 +1921,11 @@ cp_walk_subtrees (tree* tp,
       *walk_subtrees_p = 0;
       break;
 
+    case TINST_LEVEL:
+      WALK_SUBTREE (TINST_DECL (*tp));
+      *walk_subtrees_p = 0;
+      break;
+
     case PTRMEM_CST:
       WALK_SUBTREE (TREE_TYPE (*tp));
       *walk_subtrees_p = 0;
@@ -2024,7 +1948,7 @@ cp_walk_subtrees (tree* tp,
 
     default:
       input_location = save_locus;
-      return c_walk_subtrees (tp, walk_subtrees_p, func, data, htab);
+      return NULL_TREE;
     }
 
   /* We didn't find what we were looking for.  */
@@ -2050,11 +1974,11 @@ cp_cannot_inline_tree_fn (tree* fnp)
     {
       /* Don't instantiate functions that are not going to be
         inlined.  */
-      if (!DECL_INLINE (DECL_TEMPLATE_RESULT 
+      if (!DECL_INLINE (DECL_TEMPLATE_RESULT
                        (template_for_substitution (fn))))
        return 1;
 
-      fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
+      fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0, /*undefined_ok=*/0);
 
       if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
        return 1;
@@ -2111,16 +2035,6 @@ cp_add_pending_fn_decls (void* fns_p, tree prev_fn)
   return prev_fn;
 }
 
-/* Determine whether a tree node is an OVERLOAD node.  Used to decide
-   whether to copy a node or to preserve its chain when inlining a
-   function.  */
-
-int
-cp_is_overload_p (tree t)
-{
-  return TREE_CODE (t) == OVERLOAD;
-}
-
 /* Determine whether VAR is a declaration of an automatic variable in
    function FN.  */
 
@@ -2131,175 +2045,14 @@ cp_auto_var_in_fn_p (tree var, tree fn)
          && nonstatic_local_decl_p (var));
 }
 
-/* Tell whether a declaration is needed for the RESULT of a function
-   FN being inlined into CALLER or if the top node of target_exprs is
-   to be used.  */
-
-tree
-cp_copy_res_decl_for_inlining (tree result, 
-                               tree fn, 
-                               tree caller, 
-                               void* decl_map_ ATTRIBUTE_UNUSED,
-                               int* need_decl, 
-                               tree return_slot_addr)
-{
-  tree var;
-
-  /* If FN returns an aggregate then the caller will always pass the
-     address of the return slot explicitly.  If we were just to
-     create a new VAR_DECL here, then the result of this function
-     would be copied (bitwise) into the variable initialized by the
-     TARGET_EXPR.  That's incorrect, so we must transform any
-     references to the RESULT into references to the target.  */
-
-  /* We should have an explicit return slot iff the return type is
-     TREE_ADDRESSABLE.  See gimplify_aggr_init_expr.  */
-  if (TREE_ADDRESSABLE (TREE_TYPE (result))
-      != (return_slot_addr != NULL_TREE))
-    abort ();
-
-  *need_decl = !return_slot_addr;
-  if (return_slot_addr)
-    {
-      var = build_indirect_ref (return_slot_addr, "");
-      if (! same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (var),
-                                                      TREE_TYPE (result)))
-       abort ();
-    }
-  /* Otherwise, make an appropriate copy.  */
-  else
-    var = copy_decl_for_inlining (result, fn, caller);
-
-  return var;
-}
-
-/* FN body has been duplicated.  Update language specific fields.  */
-
-void
-cp_update_decl_after_saving (tree fn, 
-                             void* decl_map_)
-{
-  splay_tree decl_map = (splay_tree)decl_map_;
-  tree nrv = DECL_SAVED_FUNCTION_DATA (fn)->x_return_value;
-  if (nrv)
-    {
-      DECL_SAVED_FUNCTION_DATA (fn)->x_return_value
-       = (tree) splay_tree_lookup (decl_map, (splay_tree_key) nrv)->value;
-    }
-}
 /* Initialize tree.c.  */
 
 void
 init_tree (void)
 {
-  lang_gimplify_stmt = cp_gimplify_stmt;
   list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
 }
 
-/* Called via walk_tree.  If *TP points to a DECL_STMT for a local
-   declaration, copies the declaration and enters it in the splay_tree
-   pointed to by DATA (which is really a `splay_tree *').  */
-
-static tree
-mark_local_for_remap_r (tree* tp, 
-                        int* walk_subtrees ATTRIBUTE_UNUSED , 
-                        void* data)
-{
-  tree t = *tp;
-  splay_tree st = (splay_tree) data;
-  tree decl;
-
-  
-  if (TREE_CODE (t) == DECL_STMT
-      && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
-    decl = DECL_STMT_DECL (t);
-  else if (TREE_CODE (t) == LABEL_STMT)
-    decl = LABEL_STMT_LABEL (t);
-  else if (TREE_CODE (t) == TARGET_EXPR
-          && nonstatic_local_decl_p (TREE_OPERAND (t, 0)))
-    decl = TREE_OPERAND (t, 0);
-  else if (TREE_CODE (t) == CASE_LABEL)
-    decl = CASE_LABEL_DECL (t);
-  else
-    decl = NULL_TREE;
-
-  if (decl)
-    {
-      tree copy;
-
-      /* Make a copy.  */
-      copy = copy_decl_for_inlining (decl, 
-                                    DECL_CONTEXT (decl), 
-                                    DECL_CONTEXT (decl));
-
-      /* Remember the copy.  */
-      splay_tree_insert (st,
-                        (splay_tree_key) decl, 
-                        (splay_tree_value) copy);
-    }
-
-  return NULL_TREE;
-}
-
-/* Called via walk_tree when an expression is unsaved.  Using the
-   splay_tree pointed to by ST (which is really a `splay_tree'),
-   remaps all local declarations to appropriate replacements.  */
-
-static tree
-cp_unsave_r (tree* tp, 
-             int* walk_subtrees, 
-             void* data)
-{
-  splay_tree st = (splay_tree) data;
-  splay_tree_node n;
-
-  /* Only a local declaration (variable or label).  */
-  if (nonstatic_local_decl_p (*tp))
-    {
-      /* Lookup the declaration.  */
-      n = splay_tree_lookup (st, (splay_tree_key) *tp);
-      
-      /* If it's there, remap it.  */
-      if (n)
-       *tp = (tree) n->value;
-    }
-  else if (TREE_CODE (*tp) == SAVE_EXPR)
-    remap_save_expr (tp, st, current_function_decl, walk_subtrees);
-  else
-    {
-      copy_tree_r (tp, walk_subtrees, NULL);
-
-      /* Do whatever unsaving is required.  */
-      unsave_expr_1 (*tp);
-    }
-
-  /* Keep iterating.  */
-  return NULL_TREE;
-}
-
-/* Called whenever an expression needs to be unsaved.  */
-
-tree
-cxx_unsave_expr_now (tree tp)
-{
-  splay_tree st;
-
-  /* Create a splay-tree to map old local variable declarations to new
-     ones.  */
-  st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
-
-  /* Walk the tree once figuring out what needs to be remapped.  */
-  walk_tree (&tp, mark_local_for_remap_r, st, NULL);
-
-  /* Walk the tree again, copying, remapping, and unsaving.  */
-  walk_tree (&tp, cp_unsave_r, st, NULL);
-
-  /* Clean up.  */
-  splay_tree_delete (st);
-
-  return tp;
-}
-
 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
    is.  Note that sfk_none is zero, so this function can be used as a
    predicate to test whether or not DECL is a special function.  */
@@ -2330,22 +2083,6 @@ special_function_p (tree decl)
   return sfk_none;
 }
 
-/* Returns true if and only if NODE is a name, i.e., a node created
-   by the parser when processing an id-expression.  */
-
-bool
-name_p (tree node)
-{
-  if (TREE_CODE (node) == TEMPLATE_ID_EXPR)
-    node = TREE_OPERAND (node, 0);
-  return (/* An ordinary unqualified name.  */
-         TREE_CODE (node) == IDENTIFIER_NODE
-         /* A destructor name.  */
-         || TREE_CODE (node) == BIT_NOT_EXPR
-         /* A qualified name.  */
-         || TREE_CODE (node) == SCOPE_REF);
-}
-
 /* Returns nonzero if TYPE is a character type, including wchar_t.  */
 
 int
@@ -2430,6 +2167,19 @@ stabilize_expr (tree exp, tree* initp)
   return exp;
 }
 
+/* Add NEW, an expression whose value we don't care about, after the
+   similar expression ORIG.  */
+
+tree
+add_stmt_to_compound (tree orig, tree new)
+{
+  if (!new || !TREE_SIDE_EFFECTS (new))
+    return orig;
+  if (!orig || !TREE_SIDE_EFFECTS (orig))
+    return new;
+  return build2 (COMPOUND_EXPR, void_type_node, orig, new);
+}
+
 /* Like stabilize_expr, but for a call whose args we want to
    pre-evaluate.  */
 
@@ -2442,21 +2192,15 @@ stabilize_call (tree call, tree *initp)
   if (call == error_mark_node)
     return;
 
-  if (TREE_CODE (call) != CALL_EXPR
-      && TREE_CODE (call) != AGGR_INIT_EXPR)
-    abort ();
+  gcc_assert (TREE_CODE (call) == CALL_EXPR
+             || TREE_CODE (call) == AGGR_INIT_EXPR);
 
   for (t = TREE_OPERAND (call, 1); t; t = TREE_CHAIN (t))
     if (TREE_SIDE_EFFECTS (TREE_VALUE (t)))
       {
        tree init;
        TREE_VALUE (t) = stabilize_expr (TREE_VALUE (t), &init);
-       if (!init)
-         /* Nothing.  */;
-       else if (inits)
-         inits = build (COMPOUND_EXPR, void_type_node, inits, init);
-       else
-         inits = init;
+       inits = add_stmt_to_compound (inits, init);
       }
 
   *initp = inits;
@@ -2484,6 +2228,8 @@ stabilize_init (tree init, tree *initp)
        t = TREE_OPERAND (t, 1);
       if (TREE_CODE (t) == TARGET_EXPR)
        t = TARGET_EXPR_INITIAL (t);
+      if (TREE_CODE (t) == COMPOUND_EXPR)
+       t = expr_last (t);
       if (TREE_CODE (t) == CONSTRUCTOR
          && CONSTRUCTOR_ELTS (t) == NULL_TREE)
        {
@@ -2503,6 +2249,19 @@ stabilize_init (tree init, tree *initp)
   return true;
 }
 
+/* Like "fold", but should be used whenever we might be processing the
+   body of a template.  */
+
+tree
+fold_if_not_in_template (tree expr)
+{
+  /* In the body of a template, there is never any need to call
+     "fold".  We will call fold later when actually instantiating the
+     template.  Integral constant expressions in templates will be
+     evaluated via fold_non_dependent_expr, as necessary.  */
+  return (processing_template_decl ? expr : fold (expr));
+}
+
 \f
 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
 /* Complain that some language-specific thing hanging off a tree