OSDN Git Service

* c-common.h (check_function_format): Remove first parameter.
[pf3gnuchains/gcc-fork.git] / gcc / cp / typeck.c
index 20e602a..1dfb337 100644 (file)
@@ -1,6 +1,6 @@
 /* Build expressions with type checking for C++ compiler.
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -24,11 +24,7 @@ Boston, MA 02111-1307, USA.  */
 /* This file is part of the C++ front end.
    It contains routines to build C++ expressions given their operands,
    including computing the types of the result, C and C++ specific error
-   checks, and some optimization.
-
-   There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
-   and to process initializations in declarations (since they work
-   like a strange sort of assignment).  */
+   checks, and some optimization.  */
 
 #include "config.h"
 #include "system.h"
@@ -44,44 +40,35 @@ Boston, MA 02111-1307, USA.  */
 #include "toplev.h"
 #include "diagnostic.h"
 #include "target.h"
-
-static tree convert_for_assignment PARAMS ((tree, tree, const char *, tree,
-                                         int));
-static tree cp_pointer_int_sum PARAMS ((enum tree_code, tree, tree));
-static tree rationalize_conditional_expr PARAMS ((enum tree_code, tree));
-static int comp_target_parms PARAMS ((tree, tree));
-static int comp_ptr_ttypes_real PARAMS ((tree, tree, int));
-static int comp_ptr_ttypes_const PARAMS ((tree, tree));
-static int comp_ptr_ttypes_reinterpret PARAMS ((tree, tree));
-static int comp_except_types PARAMS ((tree, tree, int));
-static int comp_array_types PARAMS ((int (*) (tree, tree, int), tree,
-                                  tree, int));
-static tree common_base_type PARAMS ((tree, tree));
-static tree lookup_anon_field PARAMS ((tree, tree));
-static tree pointer_diff PARAMS ((tree, tree, tree));
-static tree qualify_type_recursive PARAMS ((tree, tree));
-static tree get_delta_difference PARAMS ((tree, tree, int));
-static int comp_cv_target_types PARAMS ((tree, tree, int));
-static void casts_away_constness_r PARAMS ((tree *, tree *));
-static int casts_away_constness PARAMS ((tree, tree));
-static void maybe_warn_about_returning_address_of_local PARAMS ((tree));
-static tree strip_all_pointer_quals PARAMS ((tree));
+#include "convert.h"
+
+static tree convert_for_assignment (tree, tree, const char *, tree, int);
+static tree cp_pointer_int_sum (enum tree_code, tree, tree);
+static tree rationalize_conditional_expr (enum tree_code, tree);
+static int comp_ptr_ttypes_real (tree, tree, int);
+static int comp_ptr_ttypes_const (tree, tree);
+static bool comp_except_types (tree, tree, bool);
+static bool comp_array_types (tree, tree, bool);
+static tree common_base_type (tree, tree);
+static tree pointer_diff (tree, tree, tree);
+static tree get_delta_difference (tree, tree, int);
+static void casts_away_constness_r (tree *, tree *);
+static bool casts_away_constness (tree, tree);
+static void maybe_warn_about_returning_address_of_local (tree);
 static tree lookup_destructor (tree, tree, tree);
 
 /* Return the target type of TYPE, which means return T for:
    T*, T&, T[], T (...), and otherwise, just T.  */
 
 tree
-target_type (type)
-     tree type;
+target_type (tree type)
 {
-  if (TREE_CODE (type) == REFERENCE_TYPE)
-    type = TREE_TYPE (type);
+  type = non_reference (type);
   while (TREE_CODE (type) == POINTER_TYPE
         || TREE_CODE (type) == ARRAY_TYPE
         || TREE_CODE (type) == FUNCTION_TYPE
         || TREE_CODE (type) == METHOD_TYPE
-        || TREE_CODE (type) == OFFSET_TYPE)
+        || TYPE_PTRMEM_P (type))
     type = TREE_TYPE (type);
   return type;
 }
@@ -92,8 +79,7 @@ target_type (type)
    complete type when this function returns.  */
 
 tree
-require_complete_type (value)
-     tree value;
+require_complete_type (tree value)
 {
   tree type;
 
@@ -105,21 +91,13 @@ require_complete_type (value)
   else
     type = TREE_TYPE (value);
 
+  if (type == error_mark_node)
+    return error_mark_node;
+
   /* First, detect a valid value with a complete type.  */
   if (COMPLETE_TYPE_P (type))
     return value;
 
-  /* If we see X::Y, we build an OFFSET_TYPE which has
-     not been laid out.  Try to avoid an error by interpreting
-     it as this->X::Y, if reasonable.  */
-  if (TREE_CODE (value) == OFFSET_REF
-      && current_class_ref != 0
-      && TREE_OPERAND (value, 0) == current_class_ref)
-    {
-      value = resolve_offset_ref (value);
-      return require_complete_type (value);
-    }
-
   if (complete_type_or_else (type, value))
     return value;
   else
@@ -132,8 +110,7 @@ require_complete_type (value)
    horribly wrong, in which case the error_mark_node is returned.  */
 
 tree
-complete_type (type)
-     tree type;
+complete_type (tree type)
 {
   if (type == NULL_TREE)
     /* Rather than crash, we return something sure to cause an error
@@ -145,7 +122,7 @@ complete_type (type)
   else if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type))
     {
       tree t = complete_type (TREE_TYPE (type));
-      if (COMPLETE_TYPE_P (t) && ! processing_template_decl)
+      if (COMPLETE_TYPE_P (t) && !dependent_type_p (type))
        layout_type (type);
       TYPE_NEEDS_CONSTRUCTING (type)
        = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
@@ -164,10 +141,7 @@ complete_type (type)
    Returns NULL_TREE if the type cannot be made complete.  */
 
 tree
-complete_type_or_diagnostic (type, value, diag_type)
-     tree type;
-     tree value;
-     int diag_type;
+complete_type_or_diagnostic (tree type, tree value, int diag_type)
 {
   type = complete_type (type);
   if (type == error_mark_node)
@@ -185,58 +159,12 @@ complete_type_or_diagnostic (type, value, diag_type)
 /* Return truthvalue of whether type of EXP is instantiated.  */
 
 int
-type_unknown_p (exp)
-     tree exp;
+type_unknown_p (tree exp)
 {
-  return (TREE_CODE (exp) == OVERLOAD
-          || TREE_CODE (exp) == TREE_LIST
-         || TREE_TYPE (exp) == unknown_type_node
-         || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
-             && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node));
+  return (TREE_CODE (exp) == TREE_LIST
+         || TREE_TYPE (exp) == unknown_type_node);
 }
 
-/* Return a pointer or pointer to member type similar to T1, with a
-   cv-qualification signature that is the union of the cv-qualification
-   signatures of T1 and T2: [expr.rel], [expr.eq].  */
-
-static tree
-qualify_type_recursive (t1, t2)
-     tree t1, t2;
-{
-  if ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
-      || (TYPE_PTRMEM_P (t1) && TYPE_PTRMEM_P (t2)))
-    {
-      tree tt1;
-      tree tt2;
-      tree b1;
-      int type_quals;
-      tree tgt;
-      tree attributes = (*targetm.merge_type_attributes) (t1, t2);
-
-      if (TYPE_PTRMEM_P (t1))
-       {
-         b1 = TYPE_PTRMEM_CLASS_TYPE (t1);
-         tt1 = TYPE_PTRMEM_POINTED_TO_TYPE (t1);
-         tt2 = TYPE_PTRMEM_POINTED_TO_TYPE (t2);
-       }
-      else
-       {
-         b1 = NULL_TREE;
-         tt1 = TREE_TYPE (t1);
-         tt2 = TREE_TYPE (t2);
-       }
-
-      type_quals = (cp_type_quals (tt1) | cp_type_quals (tt2));
-      tgt = qualify_type_recursive (tt1, tt2);
-      tgt = cp_build_qualified_type (tgt, type_quals);
-      if (b1)
-       t1 = build_ptrmem_type (b1, tgt);
-      else
-       t1 = build_pointer_type (tgt);
-      t1 = build_type_attribute_variant (t1, attributes);
-    }
-  return t1;
-}
 \f
 /* Return the common type of two parameter lists.
    We assume that comptypes has already been done and returned 1;
@@ -246,8 +174,7 @@ qualify_type_recursive (t1, t2)
    lists are already common.  */
 
 tree
-commonparms (p1, p2)
-     tree p1, p2;
+commonparms (tree p1, tree p2)
 {
   tree oldargs = p1, newargs, n;
   int i, len;
@@ -308,8 +235,7 @@ commonparms (p1, p2)
 /* Given a type, perhaps copied for a typedef,
    find the "original" version of it.  */
 tree
-original_type (t)
-     tree t;
+original_type (tree t)
 {
   while (TYPE_NAME (t) != NULL_TREE)
     {
@@ -329,9 +255,7 @@ original_type (t)
    T2 as described in [expr].  */
 
 tree
-type_after_usual_arithmetic_conversions (t1, t2)
-     tree t1;
-     tree t2;
+type_after_usual_arithmetic_conversions (tree t1, tree t2)
 {
   enum tree_code code1 = TREE_CODE (t1);
   enum tree_code code2 = TREE_CODE (t2);
@@ -421,7 +345,7 @@ type_after_usual_arithmetic_conversions (t1, t2)
       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_integer_type_node)
          || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_integer_type_node))
        {
-         tree t = ((TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
+         tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
                    ? long_long_unsigned_type_node 
                    : long_long_integer_type_node);
          return build_type_attribute_variant (t, attributes);
@@ -435,12 +359,12 @@ type_after_usual_arithmetic_conversions (t1, t2)
       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_integer_type_node)
          || same_type_p (TYPE_MAIN_VARIANT (t2), long_integer_type_node))
        {
-         tree t = ((TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
+         tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
                    ? long_unsigned_type_node : long_integer_type_node);
          return build_type_attribute_variant (t, attributes);
        }
       /* Otherwise prefer the unsigned one.  */
-      if (TREE_UNSIGNED (t1))
+      if (TYPE_UNSIGNED (t1))
        return build_type_attribute_variant (t1, attributes);
       else
        return build_type_attribute_variant (t2, attributes);
@@ -469,20 +393,86 @@ type_after_usual_arithmetic_conversions (t1, t2)
     }
 }
 
+/* Subroutine of composite_pointer_type to implement the recursive
+   case.  See that function for documentation fo the parameters.  */
+
+static tree
+composite_pointer_type_r (tree t1, tree t2, const char* location)
+{
+  tree pointee1;
+  tree pointee2;
+  tree result_type;
+  tree attributes;
+
+  /* Determine the types pointed to by T1 and T2.  */
+  if (TREE_CODE (t1) == POINTER_TYPE)
+    {
+      pointee1 = TREE_TYPE (t1);
+      pointee2 = TREE_TYPE (t2);
+    }
+  else
+    {
+      pointee1 = TYPE_PTRMEM_POINTED_TO_TYPE (t1);
+      pointee2 = TYPE_PTRMEM_POINTED_TO_TYPE (t2);
+    }
+
+  /* [expr.rel]
+
+     Otherwise, the composite pointer type is a pointer type
+     similar (_conv.qual_) to the type of one of the operands,
+     with a cv-qualification signature (_conv.qual_) that is the
+     union of the cv-qualification signatures of the operand
+     types.  */
+  if (same_type_ignoring_top_level_qualifiers_p (pointee1, pointee2))
+    result_type = pointee1;
+  else if ((TREE_CODE (pointee1) == POINTER_TYPE
+           && TREE_CODE (pointee2) == POINTER_TYPE)
+          || (TYPE_PTR_TO_MEMBER_P (pointee1)
+              && TYPE_PTR_TO_MEMBER_P (pointee2)))
+    result_type = composite_pointer_type_r (pointee1, pointee2, location);
+  else
+    {
+      pedwarn ("%s between distinct pointer types `%T' and `%T' "
+              "lacks a cast",
+              location, t1, t2);
+      result_type = void_type_node;
+    }
+  result_type = cp_build_qualified_type (result_type,
+                                        (cp_type_quals (pointee1)
+                                         | cp_type_quals (pointee2)));
+  /* If the original types were pointers to members, so is the
+     result.  */
+  if (TYPE_PTR_TO_MEMBER_P (t1))
+    {
+      if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
+                       TYPE_PTRMEM_CLASS_TYPE (t2)))
+       pedwarn ("%s between distinct pointer types `%T' and `%T' "
+                "lacks a cast",
+                location, t1, t2);
+      result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
+                                      result_type);
+    }
+  else
+    result_type = build_pointer_type (result_type);
+
+  /* Merge the attributes.  */
+  attributes = (*targetm.merge_type_attributes) (t1, t2);
+  return build_type_attribute_variant (result_type, attributes);
+}
+
 /* Return the composite pointer type (see [expr.rel]) for T1 and T2.
    ARG1 and ARG2 are the values with those types.  The LOCATION is a
-   string describing the current location, in case an error occurs.  */
+   string describing the current location, in case an error occurs. 
+
+   This routine also implements the computation of a common type for
+   pointers-to-members as per [expr.eq].  */
 
 tree 
-composite_pointer_type (t1, t2, arg1, arg2, location)
-     tree t1;
-     tree t2;
-     tree arg1;
-     tree arg2;
-     const char* location;
+composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2,
+                       const char* location)
 {
-  tree result_type;
-  tree attributes;
+  tree class1;
+  tree class2;
 
   /* [expr.rel]
 
@@ -493,16 +483,6 @@ composite_pointer_type (t1, t2, arg1, arg2, location)
   if (null_ptr_cst_p (arg2))
     return t1;
  
-  /* Deal with pointer-to-member functions in the same way as we deal
-     with pointers to functions.  */
-  if (TYPE_PTRMEMFUNC_P (t1))
-    t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
-  if (TYPE_PTRMEMFUNC_P (t2))
-    t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
-  
-  /* Merge the attributes.  */
-  attributes = (*targetm.merge_type_attributes) (t1, t2);
-
   /* We have:
 
        [expr.rel]
@@ -513,45 +493,78 @@ composite_pointer_type (t1, t2, arg1, arg2, location)
        and cv2.
 
     If either type is a pointer to void, make sure it is T1.  */
-  if (VOID_TYPE_P (TREE_TYPE (t2)))
+  if (TREE_CODE (t2) == POINTER_TYPE && VOID_TYPE_P (TREE_TYPE (t2)))
     {
       tree t;
       t = t1;
       t1 = t2;
       t2 = t;
     }
+
   /* Now, if T1 is a pointer to void, merge the qualifiers.  */
-  if (VOID_TYPE_P (TREE_TYPE (t1)))
+  if (TREE_CODE (t1) == POINTER_TYPE && VOID_TYPE_P (TREE_TYPE (t1)))
     {
+      tree attributes;
+      tree result_type;
+
       if (pedantic && TYPE_PTRFN_P (t2))
        pedwarn ("ISO C++ forbids %s between pointer of type `void *' and pointer-to-function", location);
-      t1 = TREE_TYPE (t1);
-      t2 = TREE_TYPE (t2);
-      result_type = cp_build_qualified_type (void_type_node,
-                                            (cp_type_quals (t1)
-                                             | cp_type_quals (t2)));
+      result_type 
+       = cp_build_qualified_type (void_type_node,
+                                  (cp_type_quals (TREE_TYPE (t1))
+                                   | cp_type_quals (TREE_TYPE (t2))));
       result_type = build_pointer_type (result_type);
+      /* Merge the attributes.  */
+      attributes = (*targetm.merge_type_attributes) (t1, t2);
+      return build_type_attribute_variant (result_type, attributes);
+    }
+
+  /* [expr.eq] permits the application of a pointer conversion to
+     bring the pointers to a common type.  */
+  if (TREE_CODE (t1) == POINTER_TYPE && TREE_CODE (t2) == POINTER_TYPE
+      && CLASS_TYPE_P (TREE_TYPE (t1))
+      && CLASS_TYPE_P (TREE_TYPE (t2))
+      && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t1),
+                                                    TREE_TYPE (t2)))
+    {
+      class1 = TREE_TYPE (t1);
+      class2 = TREE_TYPE (t2);
+
+      if (DERIVED_FROM_P (class1, class2))
+       t2 = (build_pointer_type 
+             (cp_build_qualified_type (class1, TYPE_QUALS (class2))));
+      else if (DERIVED_FROM_P (class2, class1))
+       t1 = (build_pointer_type 
+             (cp_build_qualified_type (class2, TYPE_QUALS (class1))));
+      else
+       {
+         error ("%s between distinct pointer types `%T' and `%T' "
+                "lacks a cast", location, t1, t2);
+         return error_mark_node;
+       }
     }
-  else
+  /* [expr.eq] permits the application of a pointer-to-member
+     conversion to change the class type of one of the types.  */
+  else if (TYPE_PTR_TO_MEMBER_P (t1)
+          && !same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
+                           TYPE_PTRMEM_CLASS_TYPE (t2)))
     {
-      tree full1 = qualify_type_recursive (t1, t2);
-      tree full2 = qualify_type_recursive (t2, t1);
+      class1 = TYPE_PTRMEM_CLASS_TYPE (t1);
+      class2 = TYPE_PTRMEM_CLASS_TYPE (t2);
 
-      int val = comp_target_types (full1, full2, 1);
-
-      if (val > 0)
-       result_type = full1;
-      else if (val < 0)
-       result_type = full2;
+      if (DERIVED_FROM_P (class1, class2))
+       t1 = build_ptrmem_type (class2, TYPE_PTRMEM_POINTED_TO_TYPE (t1));
+      else if (DERIVED_FROM_P (class2, class1))
+       t2 = build_ptrmem_type (class1, TYPE_PTRMEM_POINTED_TO_TYPE (t2));
       else
        {
-         pedwarn ("%s between distinct pointer types `%T' and `%T' lacks a cast",
-                     location, t1, t2);
-         result_type = ptr_type_node;
+         error ("%s between distinct pointer-to-member types `%T' and `%T' "
+                "lacks a cast", location, t1, t2);
+         return error_mark_node;
        }
     }
 
-  return build_type_attribute_variant (result_type, attributes);
+  return composite_pointer_type_r (t1, t2, location);
 }
 
 /* Return the merged type of two types.
@@ -562,11 +575,10 @@ composite_pointer_type (t1, t2, arg1, arg2, location)
    differences would cause the two types to compare unalike.  */
 
 tree
-merge_types (t1, t2)
-     tree t1, t2;
+merge_types (tree t1, tree t2)
 {
-  register enum tree_code code1;
-  register enum tree_code code2;
+  enum tree_code code1;
+  enum tree_code code2;
   tree attributes;
 
   /* Save time if the two types are the same.  */
@@ -584,8 +596,6 @@ merge_types (t1, t2)
   /* Merge the attributes.  */
   attributes = (*targetm.merge_type_attributes) (t1, t2);
 
-  /* Treat an enum type as the unsigned integer type of the same width.  */
-
   if (TYPE_PTRMEMFUNC_P (t1))
     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
   if (TYPE_PTRMEMFUNC_P (t2))
@@ -618,9 +628,14 @@ merge_types (t1, t2)
 
     case OFFSET_TYPE:
       {
-       tree base = TYPE_OFFSET_BASETYPE (t1);
-       tree target = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
-       t1 = build_offset_type (base, target);
+       int quals;
+       tree pointee;
+       quals = cp_type_quals (t1);
+       pointee = merge_types (TYPE_PTRMEM_POINTED_TO_TYPE (t1),
+                              TYPE_PTRMEM_POINTED_TO_TYPE (t2));
+       t1 = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
+                               pointee);
+       t1 = cp_build_qualified_type (t1, quals);
        break;
       }
 
@@ -649,9 +664,9 @@ merge_types (t1, t2)
 
        /* Save space: see if the result is identical to one of the args.  */
        if (valtype == TREE_TYPE (t1) && ! p2)
-         return build_type_attribute_variant (t1, attributes);
+         return cp_build_type_attribute_variant (t1, attributes);
        if (valtype == TREE_TYPE (t2) && ! p1)
-         return build_type_attribute_variant (t2, attributes);
+         return cp_build_type_attribute_variant (t2, attributes);
 
        /* Simple way if one arg fails to specify argument types.  */
        if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
@@ -659,7 +674,7 @@ merge_types (t1, t2)
            rval = build_function_type (valtype, p2);
            if ((raises = TYPE_RAISES_EXCEPTIONS (t2)))
              rval = build_exception_variant (rval, raises);
-           return build_type_attribute_variant (rval, attributes);
+           return cp_build_type_attribute_variant (rval, attributes);
          }
        raises = TYPE_RAISES_EXCEPTIONS (t1);
        if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
@@ -667,7 +682,7 @@ merge_types (t1, t2)
            rval = build_function_type (valtype, p1);
            if (raises)
              rval = build_exception_variant (rval, raises);
-           return build_type_attribute_variant (rval, attributes);
+           return cp_build_type_attribute_variant (rval, attributes);
          }
 
        rval = build_function_type (valtype, commonparms (p1, p2));
@@ -691,15 +706,21 @@ merge_types (t1, t2)
        t2 = build_function_type (TREE_TYPE (t2),
                                  TREE_CHAIN (TYPE_ARG_TYPES (t2)));
        t3 = merge_types (t1, t2);
-       t3 = build_cplus_method_type (basetype, TREE_TYPE (t3),
-                                     TYPE_ARG_TYPES (t3));
+       t3 = build_method_type_directly (basetype, TREE_TYPE (t3),
+                                        TYPE_ARG_TYPES (t3));
        t1 = build_exception_variant (t3, raises);
        break;
       }
 
+    case TYPENAME_TYPE:
+      /* There is no need to merge attributes into a TYPENAME_TYPE.
+        When the type is instantiated it will have whatever
+        attributes result from the instantiation.  */
+      return t1;
+
     default:;
     }
-  return build_type_attribute_variant (t1, attributes);
+  return cp_build_type_attribute_variant (t1, attributes);
 }
 
 /* Return the common type of two types.
@@ -710,8 +731,7 @@ merge_types (t1, t2)
    if the operands have the given two types.  */
 
 tree
-common_type (t1, t2)
-     tree t1, t2;
+common_type (tree t1, tree t2)
 {
   enum tree_code code1;
   enum tree_code code2;
@@ -734,18 +754,18 @@ common_type (t1, t2)
           || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)))
     return composite_pointer_type (t1, t2, error_mark_node, error_mark_node,
                                   "conversion");
-
   else
     abort ();
 }
 \f
 /* Compare two exception specifier types for exactness or subsetness, if
-   allowed. Returns 0 for mismatch, 1 for same, 2 if B is allowed by A.
+   allowed. Returns false for mismatch, true for match (same, or
+   derived and !exact).
  
    [except.spec] "If a class X ... objects of class X or any class publicly
-   and unambigously derrived from X. Similarly, if a pointer type Y * ...
+   and unambiguously derived from X. Similarly, if a pointer type Y * ...
    exceptions of type Y * or that are pointers to any type publicly and
-   unambigously derrived from Y. Otherwise a function only allows exceptions
+   unambiguously derived from Y. Otherwise a function only allows exceptions
    that have the same type ..."
    This does not mention cv qualifiers and is different to what throw
    [except.throw] and catch [except.catch] will do. They will ignore the
@@ -754,17 +774,15 @@ common_type (t1, t2)
    
    We implement the letter of the standard.  */
 
-static int
-comp_except_types (a, b, exact)
-     tree a, b;
-     int exact;
+static bool
+comp_except_types (tree a, tree b, bool exact)
 {
   if (same_type_p (a, b))
-    return 1;
+    return true;
   else if (!exact)
     {
       if (cp_type_quals (a) || cp_type_quals (b))
-        return 0;
+        return false;
       
       if (TREE_CODE (a) == POINTER_TYPE
           && TREE_CODE (b) == POINTER_TYPE)
@@ -772,43 +790,41 @@ comp_except_types (a, b, exact)
           a = TREE_TYPE (a);
           b = TREE_TYPE (b);
           if (cp_type_quals (a) || cp_type_quals (b))
-            return 0;
+            return false;
         }
       
       if (TREE_CODE (a) != RECORD_TYPE
           || TREE_CODE (b) != RECORD_TYPE)
-        return 0;
+        return false;
       
       if (ACCESSIBLY_UNIQUELY_DERIVED_P (a, b))
-        return 2;
+        return true;
     }
-  return 0;
+  return false;
 }
 
-/* Return 1 if TYPE1 and TYPE2 are equivalent exception specifiers.
-   If EXACT is 0, T2 can be stricter than T1 (according to 15.4/7),
+/* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
+   If EXACT is false, T2 can be stricter than T1 (according to 15.4/7),
    otherwise it must be exact. Exception lists are unordered, but
    we've already filtered out duplicates. Most lists will be in order,
    we should try to make use of that.  */
 
-int
-comp_except_specs (t1, t2, exact)
-     tree t1, t2;
-     int exact;
+bool
+comp_except_specs (tree t1, tree t2, bool exact)
 {
   tree probe;
   tree base;
   int  length = 0;
 
   if (t1 == t2)
-    return 1;
+    return true;
   
   if (t1 == NULL_TREE)              /* T1 is ...  */
     return t2 == NULL_TREE || !exact;
   if (!TREE_VALUE (t1)) /* t1 is EMPTY */
     return t2 != NULL_TREE && !TREE_VALUE (t2);
   if (t2 == NULL_TREE)              /* T2 is ...  */
-    return 0;
+    return false;
   if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
     return !exact;
   
@@ -832,37 +848,33 @@ comp_except_specs (t1, t2, exact)
             }
         }
       if (probe == NULL_TREE)
-        return 0;
+        return false;
     }
   return !exact || base == NULL_TREE || length == list_length (t1);
 }
 
-/* Compare the array types T1 and T2, using CMP as the type comparison
-   function for the element types.  STRICT is as for comptypes.  */
+/* Compare the array types T1 and T2.  ALLOW_REDECLARATION is true if
+   [] can match [size].  */
 
-static int
-comp_array_types (cmp, t1, t2, strict)
-     register int (*cmp) PARAMS ((tree, tree, int));
-     tree t1, t2;
-     int strict;
+static bool
+comp_array_types (tree t1, tree t2, bool allow_redeclaration)
 {
   tree d1;
   tree d2;
+  tree max1, max2;
 
   if (t1 == t2)
-    return 1;
+    return true;
 
   /* The type of the array elements must be the same.  */
-  if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
-       || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), 
-                  strict & ~COMPARE_REDECLARATION)))
-    return 0;
+  if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
+    return false;
 
   d1 = TYPE_DOMAIN (t1);
   d2 = TYPE_DOMAIN (t2);
 
   if (d1 == d2)
-    return 1;
+    return true;
 
   /* If one of the arrays is dimensionless, and the other has a
      dimension, they are of different types.  However, it is valid to
@@ -877,108 +889,102 @@ comp_array_types (cmp, t1, t2, strict)
        array types that differ by the presence or absence of a major
        array bound (_dcl.array_).  */
   if (!d1 || !d2)
-    return strict & COMPARE_REDECLARATION;
+    return allow_redeclaration;
 
   /* Check that the dimensions are the same.  */
-  return (cp_tree_equal (TYPE_MIN_VALUE (d1),
-                        TYPE_MIN_VALUE (d2))
-         && cp_tree_equal (TYPE_MAX_VALUE (d1),
-                           TYPE_MAX_VALUE (d2)));
-}
-
-/* Return 1 if T1 and T2 are compatible types for assignment or
-   various other operations.  STRICT is a bitwise-or of the COMPARE_*
-   flags.  */
 
-int
-comptypes (t1, t2, strict)
-     tree t1;
-     tree t2;
-     int strict;
-{
-  int attrval, val;
-  int orig_strict = strict;
+  if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
+    return false;
+  max1 = TYPE_MAX_VALUE (d1);
+  max2 = TYPE_MAX_VALUE (d2);
+  if (processing_template_decl && !abi_version_at_least (2)
+      && !value_dependent_expression_p (max1)
+      && !value_dependent_expression_p (max2))
+    {
+      /* With abi-1 we do not fold non-dependent array bounds, (and
+         consequently mangle them incorrectly).  We must therefore
+         fold them here, to verify the domains have the same
+         value.  */
+      max1 = fold (max1);
+      max2 = fold (max2);
+    }
 
-  /* The special exemption for redeclaring array types without an
-     array bound only applies at the top level:
+  if (!cp_tree_equal (max1, max2))
+    return false;
 
-       extern int (*i)[];
-       int (*i)[8];
+  return true;
+}
 
-     is invalid, for example.  */
-  strict &= ~COMPARE_REDECLARATION;
+/* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
+   is a bitwise-or of the COMPARE_* flags.  */
 
-  /* Suppress errors caused by previously reported errors */
+bool
+comptypes (tree t1, tree t2, int strict)
+{
   if (t1 == t2)
-    return 1;
+    return true;
+
+  /* Suppress errors caused by previously reported errors.  */
+  if (t1 == error_mark_node || t2 == error_mark_node)
+    return false;
+  
+  my_friendly_assert (TYPE_P (t1) && TYPE_P (t2), 20030623);
+  
+  /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
+     current instantiation.  */
+  if (TREE_CODE (t1) == TYPENAME_TYPE)
+    {
+      tree resolved = resolve_typename_type (t1, /*only_current_p=*/true);
 
-  /* This should never happen.  */
-  my_friendly_assert (t1 != error_mark_node, 307);
+      if (resolved != error_mark_node)
+       t1 = resolved;
+    }
+  
+  if (TREE_CODE (t2) == TYPENAME_TYPE)
+    {
+      tree resolved = resolve_typename_type (t2, /*only_current_p=*/true);
 
-  if (t2 == error_mark_node)
-    return 0;
+      if (resolved != error_mark_node)
+       t2 = resolved;
+    }
 
-  /* If either type is the internal version of sizetype, return the
+  /* If either type is the internal version of sizetype, use the
      language version.  */
   if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
-      && TYPE_DOMAIN (t1) != 0)
-    t1 = TYPE_DOMAIN (t1);
+      && TYPE_ORIG_SIZE_TYPE (t1))
+    t1 = TYPE_ORIG_SIZE_TYPE (t1);
 
   if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
-      && TYPE_DOMAIN (t2) != 0)
-    t2 = TYPE_DOMAIN (t2);
-
-  if (strict & COMPARE_RELAXED)
-    {
-      /* Treat an enum type as the unsigned integer type of the same width.  */
-
-      if (TREE_CODE (t1) == ENUMERAL_TYPE)
-       t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
-      if (TREE_CODE (t2) == ENUMERAL_TYPE)
-       t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
-
-      if (t1 == t2)
-       return 1;
-    }
+      && TYPE_ORIG_SIZE_TYPE (t2))
+    t2 = TYPE_ORIG_SIZE_TYPE (t2);
 
   if (TYPE_PTRMEMFUNC_P (t1))
     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
   if (TYPE_PTRMEMFUNC_P (t2))
     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
 
-  /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
-     current instantiation.  */
-  if (TREE_CODE (t1) == TYPENAME_TYPE)
-    t1 = resolve_typename_type_in_current_instantiation (t1);
-  if (TREE_CODE (t2) == TYPENAME_TYPE)
-    t2 = resolve_typename_type_in_current_instantiation (t2);
-
   /* Different classes of types can't be compatible.  */
   if (TREE_CODE (t1) != TREE_CODE (t2))
-    return 0;
+    return false;
 
-  /* Qualifiers must match.  */
-  if (cp_type_quals (t1) != cp_type_quals (t2))
-    return 0;
-  if (strict == COMPARE_STRICT 
-      && TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
-    return 0;
+  /* Qualifiers must match.  For array types, we will check when we
+     recur on the array element types.  */
+  if (TREE_CODE (t1) != ARRAY_TYPE
+      && TYPE_QUALS (t1) != TYPE_QUALS (t2))
+    return false;
+  if (TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
+    return false;
 
   /* Allow for two different type nodes which have essentially the same
      definition.  Note that we already checked for equality of the type
      qualifiers (just above).  */
 
-  if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
-    return 1;
-
-  if (strict & COMPARE_NO_ATTRIBUTES)
-    attrval = 1;
-  /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
-  else if (! (attrval = (*targetm.comp_type_attributes) (t1, t2)))
-     return 0;
+  if (TREE_CODE (t1) != ARRAY_TYPE
+      && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
+    return true;
 
-  /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
-  val = 0;
+  if (!(*targetm.comp_type_attributes) (t1, t2))
+    return false;
 
   switch (TREE_CODE (t1))
     {
@@ -986,335 +992,119 @@ comptypes (t1, t2, strict)
     case BOUND_TEMPLATE_TEMPLATE_PARM:
       if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
          || TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
-       return 0;
-      if (! comp_template_parms
-             (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
-              DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
-       return 0;
+       return false;
+      if (!comp_template_parms
+         (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
+          DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
+       return false;
       if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
-       return 1;
+       return true;
       /* Don't check inheritance.  */
       strict = COMPARE_STRICT;
-      /* fall through */
+      /* Fall through.  */
 
     case RECORD_TYPE:
     case UNION_TYPE:
       if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
          && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
-             || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM))
-       val = comp_template_args (TYPE_TI_ARGS (t1),
-                                 TYPE_TI_ARGS (t2));
-    look_hard:
+             || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
+         && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
+       return true;
+      
       if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
-       val = 1;
-      else if ((strict & COMPARE_RELAXED) && DERIVED_FROM_P (t2, t1))
-       val = 1;
-      break;
+       return true;
+      else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
+       return true;
+      
+      return false;
 
     case OFFSET_TYPE:
-      val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)),
-                       build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict)
-            && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
-      break;
+      if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
+                     strict & ~COMPARE_REDECLARATION))
+       return false;
+      /* Fall through.  */
 
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-      t1 = TREE_TYPE (t1);
-      t2 = TREE_TYPE (t2);
-      /* first, check whether the referred types match with the
-         required level of strictness */
-      val = comptypes (t1, t2, strict);
-      if (val)
-       break;
-      if (TREE_CODE (t1) == RECORD_TYPE 
-         && TREE_CODE (t2) == RECORD_TYPE)
-       goto look_hard;
-      break;
+      return same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
 
     case METHOD_TYPE:
     case FUNCTION_TYPE:
-      val = ((TREE_TYPE (t1) == TREE_TYPE (t2)
-             || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
-            && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)));
-      break;
+      if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
+       return false;
+      return compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2));
 
     case ARRAY_TYPE:
-      /* Target types must match incl. qualifiers.  We use ORIG_STRICT
-        here since this is the one place where
-        COMPARE_REDECLARATION should be used.  */
-      val = comp_array_types (comptypes, t1, t2, orig_strict);
-      break;
+      /* Target types must match incl. qualifiers.  */
+      return comp_array_types (t1, t2, !!(strict & COMPARE_REDECLARATION));
 
     case TEMPLATE_TYPE_PARM:
-      return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2)
-       && TEMPLATE_TYPE_LEVEL (t1) == TEMPLATE_TYPE_LEVEL (t2);
+      return (TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2)
+             && TEMPLATE_TYPE_LEVEL (t1) == TEMPLATE_TYPE_LEVEL (t2));
 
     case TYPENAME_TYPE:
-      if (cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
-                         TYPENAME_TYPE_FULLNAME (t2)) < 1)
-        return 0;
+      if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
+                         TYPENAME_TYPE_FULLNAME (t2)))
+        return false;
       return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2));
 
     case UNBOUND_CLASS_TEMPLATE:
-      if (cp_tree_equal (TYPE_IDENTIFIER (t1),
-                         TYPE_IDENTIFIER (t2)) < 1)
-        return 0;
+      if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
+        return false;
       return same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2));
 
     case COMPLEX_TYPE:
       return same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
 
-    default:
+    case VECTOR_TYPE:
+      return TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
+            && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2));
       break;
-    }
-  return attrval == 2 && val == 1 ? 2 : val;
-}
-
-/* Subroutine of comp_target-types.  Make sure that the cv-quals change
-   only in the same direction as the target type.  */
-
-static int
-comp_cv_target_types (ttl, ttr, nptrs)
-     tree ttl, ttr;
-     int nptrs;
-{
-  int t;
-
-  if (!at_least_as_qualified_p (ttl, ttr)
-      && !at_least_as_qualified_p (ttr, ttl))
-    /* The qualifications are incomparable.  */
-    return 0;
-
-  if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr))
-    return more_qualified_p (ttr, ttl) ? -1 : 1;
-
-  t = comp_target_types (ttl, ttr, nptrs);
-  if ((t == 1 && at_least_as_qualified_p (ttl, ttr)) 
-      || (t == -1 && at_least_as_qualified_p (ttr, ttl)))
-    return t;
-
-  return 0;
-}
-
-/* Return 1 or -1 if TTL and TTR are pointers to types that are equivalent,
-   ignoring their qualifiers, 0 if not. Return 1 means that TTR can be
-   converted to TTL. Return -1 means that TTL can be converted to TTR but
-   not vice versa.
-
-   NPTRS is the number of pointers we can strip off and keep cool.
-   This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
-   but to not permit B** to convert to A**.
-
-   This should go away.  Callers should use can_convert or something
-   similar instead.  (jason 17 Apr 1997)  */
-
-int
-comp_target_types (ttl, ttr, nptrs)
-     tree ttl, ttr;
-     int nptrs;
-{
-  ttl = TYPE_MAIN_VARIANT (ttl);
-  ttr = TYPE_MAIN_VARIANT (ttr);
-  if (same_type_p (ttl, ttr))
-    return 1;
-
-  if (TREE_CODE (ttr) != TREE_CODE (ttl))
-    return 0;
-
-  if ((TREE_CODE (ttr) == POINTER_TYPE
-       || TREE_CODE (ttr) == REFERENCE_TYPE)
-      /* If we get a pointer with nptrs == 0, we don't allow any tweaking
-        of the type pointed to.  This is necessary for reference init
-        semantics.  We won't get here from a previous call with nptrs == 1;
-        for multi-level pointers we end up in comp_ptr_ttypes.  */
-      && nptrs > 0)
-    {
-      int is_ptr = TREE_CODE (ttr) == POINTER_TYPE;
-
-      ttl = TREE_TYPE (ttl);
-      ttr = TREE_TYPE (ttr);
-
-      if (is_ptr)
-       {
-         if (TREE_CODE (ttl) == UNKNOWN_TYPE
-             || TREE_CODE (ttr) == UNKNOWN_TYPE)
-           return 1;
-         else if (TREE_CODE (ttl) == VOID_TYPE
-                  && TREE_CODE (ttr) != FUNCTION_TYPE
-                  && TREE_CODE (ttr) != METHOD_TYPE
-                  && TREE_CODE (ttr) != OFFSET_TYPE)
-           return 1;
-         else if (TREE_CODE (ttr) == VOID_TYPE
-                  && TREE_CODE (ttl) != FUNCTION_TYPE
-                  && TREE_CODE (ttl) != METHOD_TYPE
-                  && TREE_CODE (ttl) != OFFSET_TYPE)
-           return -1;
-         else if (TREE_CODE (ttl) == POINTER_TYPE
-                  || TREE_CODE (ttl) == ARRAY_TYPE)
-           {
-             if (comp_ptr_ttypes (ttl, ttr))
-               return 1;
-             else if (comp_ptr_ttypes (ttr, ttl))
-               return -1;
-             return 0;
-           }
-       }
-
-      /* Const and volatile mean something different for function types,
-        so the usual checks are not appropriate.  */
-      if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE)
-       return comp_target_types (ttl, ttr, nptrs - 1);
-
-      return comp_cv_target_types (ttl, ttr, nptrs - 1);
-    }
-
-  if (TREE_CODE (ttr) == ARRAY_TYPE)
-    return comp_array_types (comp_target_types, ttl, ttr, COMPARE_STRICT);
-  else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
-    {
-      tree argsl, argsr;
-      int saw_contra = 0;
-
-      if (pedantic)
-       {
-         if (!same_type_p (TREE_TYPE (ttl), TREE_TYPE (ttr)))
-           return 0;
-       }
-      else
-       {
-         switch (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), -1))
-           {
-           case 0:
-             return 0;
-           case -1:
-             saw_contra = 1;
-           }
-       }
-
-      argsl = TYPE_ARG_TYPES (ttl);
-      argsr = TYPE_ARG_TYPES (ttr);
-
-      /* Compare 'this' here, not in comp_target_parms.  */
-      if (TREE_CODE (ttr) == METHOD_TYPE)
-       {
-         tree tl = TYPE_METHOD_BASETYPE (ttl);
-         tree tr = TYPE_METHOD_BASETYPE (ttr);
-
-         if (!same_or_base_type_p (tr, tl))
-           {
-             if (same_or_base_type_p (tl, tr))
-               saw_contra = 1;
-             else
-               return 0;
-           }
-
-         argsl = TREE_CHAIN (argsl);
-         argsr = TREE_CHAIN (argsr);
-       }
 
-       switch (comp_target_parms (argsl, argsr))
-         {
-         case 0:
-           return 0;
-         case -1:
-           saw_contra = 1;
-         }
-
-       return saw_contra ? -1 : 1;
-    }
-  /* for C++ */
-  else if (TREE_CODE (ttr) == OFFSET_TYPE)
-    {
-      int base;
-
-      /* Contravariance: we can assign a pointer to base member to a pointer
-        to derived member.  Note difference from simple pointer case, where
-        we can pass a pointer to derived to a pointer to base.  */
-      if (same_or_base_type_p (TYPE_OFFSET_BASETYPE (ttr),
-                              TYPE_OFFSET_BASETYPE (ttl)))
-       base = 1;
-      else if (same_or_base_type_p (TYPE_OFFSET_BASETYPE (ttl),
-                                   TYPE_OFFSET_BASETYPE (ttr)))
-       {
-         tree tmp = ttl;
-         ttl = ttr;
-         ttr = tmp;
-         base = -1;
-       }
-      else
-       return 0;
-
-      ttl = TREE_TYPE (ttl);
-      ttr = TREE_TYPE (ttr);
-
-      if (TREE_CODE (ttl) == POINTER_TYPE
-         || TREE_CODE (ttl) == ARRAY_TYPE)
-       {
-         if (comp_ptr_ttypes (ttl, ttr))
-           return base;
-         return 0;
-       }
-      else
-       {
-         if (comp_cv_target_types (ttl, ttr, nptrs) == 1)
-           return base;
-         return 0;
-       }
-    }
-  else if (IS_AGGR_TYPE (ttl))
-    {
-      if (nptrs < 0)
-       return 0;
-      if (same_or_base_type_p (build_pointer_type (ttl), 
-                              build_pointer_type (ttr)))
-       return 1;
-      if (same_or_base_type_p (build_pointer_type (ttr), 
-                              build_pointer_type (ttl)))
-       return -1;
-      return 0;
+    default:
+      break;
     }
-
-  return 0;
+  return false;
 }
 
 /* Returns 1 if TYPE1 is at least as qualified as TYPE2.  */
 
-int
-at_least_as_qualified_p (type1, type2)
-     tree type1;
-     tree type2;
+bool
+at_least_as_qualified_p (tree type1, tree type2)
 {
+  int q1 = cp_type_quals (type1);
+  int q2 = cp_type_quals (type2);
+  
   /* All qualifiers for TYPE2 must also appear in TYPE1.  */
-  return ((cp_type_quals (type1) & cp_type_quals (type2))
-         == cp_type_quals (type2));
+  return (q1 & q2) == q2;
 }
 
 /* Returns 1 if TYPE1 is more qualified than TYPE2.  */
 
-int
-more_qualified_p (type1, type2)
-     tree type1;
-     tree type2;
+bool
+more_qualified_p (tree type1, tree type2)
 {
-  return (cp_type_quals (type1) != cp_type_quals (type2)
-         && at_least_as_qualified_p (type1, type2));
+  int q1 = cp_type_quals (type1);
+  int q2 = cp_type_quals (type2);
+
+  return q1 != q2 && (q1 & q2) == q2;
 }
 
 /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
    more cv-qualified that TYPE1, and 0 otherwise.  */
 
 int
-comp_cv_qualification (type1, type2)
-     tree type1;
-     tree type2;
+comp_cv_qualification (tree type1, tree type2)
 {
-  if (cp_type_quals (type1) == cp_type_quals (type2))
+  int q1 = cp_type_quals (type1);
+  int q2 = cp_type_quals (type2);
+
+  if (q1 == q2)
     return 0;
 
-  if (at_least_as_qualified_p (type1, type2))
+  if ((q1 & q2) == q2)
     return 1;
-
-  else if (at_least_as_qualified_p (type2, type1))
+  else if ((q1 & q2) == q1)
     return -1;
 
   return 0;
@@ -1325,9 +1115,7 @@ comp_cv_qualification (type1, type2)
    are similar.  Returns -1 if the other way 'round, and 0 otherwise.  */
 
 int
-comp_cv_qual_signature (type1, type2)
-     tree type1;
-     tree type2;
+comp_cv_qual_signature (tree type1, tree type2)
 {
   if (comp_ptr_ttypes_real (type2, type1, -1))
     return 1;
@@ -1342,8 +1130,7 @@ comp_cv_qual_signature (type1, type2)
    returns ERROR_MARK_NODE.  */
 
 static tree
-common_base_type (tt1, tt2)
-     tree tt1, tt2;
+common_base_type (tree tt1, tree tt2)
 {
   tree best = NULL_TREE;
   int i;
@@ -1391,133 +1178,58 @@ common_base_type (tt1, tt2)
 \f
 /* Subroutines of `comptypes'.  */
 
-/* Return 1 if two parameter type lists PARMS1 and PARMS2 are
+/* Return true if two parameter type lists PARMS1 and PARMS2 are
    equivalent in the sense that functions with those parameter types
    can have equivalent types.  The two lists must be equivalent,
-   element by element.
-
-   C++: See comment above about TYPE1, TYPE2.  */
+   element by element.  */
 
-int
-compparms (parms1, parms2)
-     tree parms1, parms2;
+bool
+compparms (tree parms1, tree parms2)
 {
-  register tree t1 = parms1, t2 = parms2;
+  tree t1, t2;
 
   /* An unspecified parmlist matches any specified parmlist
      whose argument types don't need default promotions.  */
 
-  while (1)
+  for (t1 = parms1, t2 = parms2;
+       t1 || t2;
+       t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
     {
-      if (t1 == 0 && t2 == 0)
-       return 1;
       /* If one parmlist is shorter than the other,
         they fail to match.  */
-      if (t1 == 0 || t2 == 0)
-       return 0;
-      if (!same_type_p (TREE_VALUE (t2), TREE_VALUE (t1)))
-       return 0;
-
-      t1 = TREE_CHAIN (t1);
-      t2 = TREE_CHAIN (t2);
+      if (!t1 || !t2)
+       return false;
+      if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
+       return false;
     }
+  return true;
 }
 
-/* This really wants return whether or not parameter type lists
-   would make their owning functions assignment compatible or not.
-
-   The return value is like for comp_target_types.
-
-   This should go away, possibly with the exception of the empty parmlist
-   conversion; there are no conversions between function types in C++.
-   (jason 17 Apr 1997)  */
-
-static int
-comp_target_parms (parms1, parms2)
-     tree parms1, parms2;
-{
-  register tree t1 = parms1, t2 = parms2;
-  int warn_contravariance = 0;
-
-  /* In C, an unspecified parmlist matches any specified parmlist
-     whose argument types don't need default promotions.  This is not
-     true for C++, but let's do it anyway for unfixed headers.  */
-
-  if (t1 == 0 && t2 != 0)
-    {
-      pedwarn ("ISO C++ prohibits conversion from `%#T' to `(...)'",
-                 parms2);
-      return self_promoting_args_p (t2);
-    }
-  if (t2 == 0)
-    return self_promoting_args_p (t1);
-
-  for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
-    {
-      tree p1, p2;
-
-      /* If one parmlist is shorter than the other,
-        they fail to match, unless STRICT is <= 0.  */
-      if (t1 == 0 || t2 == 0)
-       return 0;
-      p1 = TREE_VALUE (t1);
-      p2 = TREE_VALUE (t2);
-      if (same_type_p (p1, p2))
-       continue;
-
-      if (pedantic)
-       return 0;
-
-      if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
-         || (TREE_CODE (p1) == REFERENCE_TYPE
-             && TREE_CODE (p2) == REFERENCE_TYPE))
-       {
-         /* The following is wrong for contravariance,
-            but many programs depend on it.  */
-         if (TREE_TYPE (p1) == void_type_node)
-           continue;
-         if (TREE_TYPE (p2) == void_type_node)
-           {
-             warn_contravariance = 1;
-             continue;
-           }
-         if (IS_AGGR_TYPE (TREE_TYPE (p1))
-             && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (p1),
-                                                            TREE_TYPE (p2)))
-           return 0;
-       }
-      /* Note backwards order due to contravariance.  */
-      if (comp_target_types (p2, p1, 1) <= 0)
-       {
-         if (comp_target_types (p1, p2, 1) > 0)
-           {
-             warn_contravariance = 1;
-             continue;
-           }
-         return 0;
-       }
-    }
-  return warn_contravariance ? -1 : 1;
-}
 \f
+/* Process a sizeof or alignof expression where the operand is a
+   type.  */
+
 tree
-cxx_sizeof_or_alignof_type (type, op, complain)
-     tree type;
-     enum tree_code op;
-     int complain;
+cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
 {
   enum tree_code type_code;
   tree value;
   const char *op_name;
 
   my_friendly_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR, 20020720);
+  if (type == error_mark_node)
+    return error_mark_node;
+  
   if (processing_template_decl)
-    return build_min_nt (op, type);
+    {
+      value = build_min (op, size_type_node, type);
+      TREE_READONLY (value) = 1;
+      return value;
+    }
   
   op_name = operator_name_info[(int) op].name;
-  
-  if (TREE_CODE (type) == REFERENCE_TYPE)
-    type = TREE_TYPE (type);
+
+  type = non_reference (type);
   type_code = TREE_CODE (type);
 
   if (type_code == METHOD_TYPE)
@@ -1526,66 +1238,94 @@ cxx_sizeof_or_alignof_type (type, op, complain)
        pedwarn ("invalid application of `%s' to a member function", op_name);
       value = size_one_node;
     }
-  else if (type_code == OFFSET_TYPE)
-    {
-      if (complain)
-       error ("invalid application of `%s' to non-static member", op_name);
-      value = size_zero_node;
-    }
   else
     value = c_sizeof_or_alignof_type (complete_type (type), op, complain);
 
   return value;
 }
 
+/* Process a sizeof or alignof expression where the operand is an
+   expression.  */
+
 tree
-expr_sizeof (e)
-     tree e;
+cxx_sizeof_or_alignof_expr (tree e, enum tree_code op)
 {
+  const char *op_name = operator_name_info[(int) op].name;
+  
+  if (e == error_mark_node)
+    return error_mark_node;
+  
   if (processing_template_decl)
-    return build_min_nt (SIZEOF_EXPR, e);
-
+    {
+      e = build_min (op, size_type_node, e);
+      TREE_SIDE_EFFECTS (e) = 0;
+      TREE_READONLY (e) = 1;
+      
+      return e;
+    }
+  
   if (TREE_CODE (e) == COMPONENT_REF
+      && TREE_CODE (TREE_OPERAND (e, 1)) == FIELD_DECL
       && DECL_C_BIT_FIELD (TREE_OPERAND (e, 1)))
-    error ("sizeof applied to a bit-field");
-  if (is_overloaded_fn (e))
     {
-      pedwarn ("ISO C++ forbids applying `sizeof' to an expression of function type");
-      return c_sizeof (char_type_node);
+      error ("invalid application of `%s' to a bit-field", op_name);
+      e = char_type_node;
+    }
+  else if (is_overloaded_fn (e))
+    {
+      pedwarn ("ISO C++ forbids applying `%s' to an expression of function type", op_name);
+      e = char_type_node;
     }
   else if (type_unknown_p (e))
     {
       cxx_incomplete_type_error (e, TREE_TYPE (e));
-      return c_sizeof (char_type_node);
+      e = char_type_node;
     }
-  /* It's invalid to say `sizeof (X::i)' for `i' a non-static data
-     member unless you're in a non-static member of X.  So hand off to
-     resolve_offset_ref.  [expr.prim]  */
-  else if (TREE_CODE (e) == OFFSET_REF)
-    e = resolve_offset_ref (e);
-
-  if (e == error_mark_node)
-    return e;
-
-  return cxx_sizeof (TREE_TYPE (e));
+  else
+    e = TREE_TYPE (e);
+  
+  return cxx_sizeof_or_alignof_type (e, op, true);
 }
   
 \f
-/* Perform the array-to-pointer and function-to-pointer conversions
-   for EXP.  
+/* EXPR is being used in a context that is not a function call.
+   Enforce:
 
-   In addition, references are converted to lvalues and manifest
-   constants are replaced by their values.  */
+     [expr.ref] 
 
-tree
-decay_conversion (exp)
-     tree exp;
+     The expression can be used only as the left-hand operand of a
+     member function call.  
+
+     [expr.mptr.operator]
+
+     If the result of .* or ->* is a function, then that result can be
+     used only as the operand for the function call operator ().  
+
+   by issuing an error message if appropriate.  Returns true iff EXPR
+   violates these rules.  */
+
+bool
+invalid_nonstatic_memfn_p (tree expr)
 {
-  register tree type;
-  register enum tree_code code;
+  if (TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE)
+    {
+      error ("invalid use of non-static member function");
+      return true;
+    }
+  return false;
+}
 
-  if (TREE_CODE (exp) == OFFSET_REF)
-    exp = resolve_offset_ref (exp);
+/* Perform the conversions in [expr] that apply when an lvalue appears
+   in an rvalue context: the lvalue-to-rvalue, array-to-pointer, and
+   function-to-pointer conversions.
+
+   In addition manifest constants are replaced by their values.  */
+
+tree
+decay_conversion (tree exp)
+{
+  tree type;
+  enum tree_code code;
 
   type = TREE_TYPE (exp);
   code = TREE_CODE (type);
@@ -1627,30 +1367,18 @@ decay_conversion (exp)
       error ("void value not ignored as it ought to be");
       return error_mark_node;
     }
-  if (code == METHOD_TYPE)
-    abort ();
+  if (invalid_nonstatic_memfn_p (exp))
+    return error_mark_node;
   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
     return build_unary_op (ADDR_EXPR, exp, 0);
   if (code == ARRAY_TYPE)
     {
-      register tree adr;
+      tree adr;
       tree ptrtype;
 
       if (TREE_CODE (exp) == INDIRECT_REF)
-       {
-         /* Stripping away the INDIRECT_REF is not the right
-            thing to do for references...  */
-         tree inner = TREE_OPERAND (exp, 0);
-         if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
-           {
-             inner = build1 (CONVERT_EXPR,
-                             build_pointer_type (TREE_TYPE
-                                                 (TREE_TYPE (inner))),
-                             inner);
-             TREE_CONSTANT (inner) = TREE_CONSTANT (TREE_OPERAND (inner, 0));
-           }
-         return cp_convert (build_pointer_type (TREE_TYPE (type)), inner);
-       }
+       return build_nop (build_pointer_type (TREE_TYPE (type)), 
+                         TREE_OPERAND (exp, 0));
 
       if (TREE_CODE (exp) == COMPOUND_EXPR)
        {
@@ -1670,15 +1398,9 @@ decay_conversion (exp)
 
       if (TREE_CODE (exp) == VAR_DECL)
        {
-         /* ??? This is not really quite correct
-            in that the type of the operand of ADDR_EXPR
-            is not the target type of the type of the ADDR_EXPR itself.
-            Question is, can this lossage be avoided?  */
-         adr = build1 (ADDR_EXPR, ptrtype, exp);
          if (!cxx_mark_addressable (exp))
            return error_mark_node;
-         TREE_CONSTANT (adr) = staticp (exp);
-         TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
+         adr = build_nop (ptrtype, build_address (exp));
          return adr;
        }
       /* This way is better for a COMPONENT_REF since it can
@@ -1696,33 +1418,39 @@ decay_conversion (exp)
 }
 
 tree
-default_conversion (exp)
-     tree exp;
+default_conversion (tree exp)
 {
-  tree type;
-  enum tree_code code;
-
   exp = decay_conversion (exp);
 
-  type = TREE_TYPE (exp);
-  code = TREE_CODE (type);
-
-  if (INTEGRAL_CODE_P (code))
-    {
-      tree t = type_promotes_to (type);
-      if (t != type)
-       return cp_convert (t, exp);
-    }
+  if (INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
+    exp = perform_integral_promotions (exp);
 
   return exp;
 }
 
+/* EXPR is an expression with an integral or enumeration type.
+   Perform the integral promotions in [conv.prom], and return the
+   converted value.  */
+
+tree
+perform_integral_promotions (tree expr)
+{
+  tree type;
+  tree promoted_type;
+
+  type = TREE_TYPE (expr);
+  my_friendly_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type), 20030703);
+  promoted_type = type_promotes_to (type);
+  if (type != promoted_type)
+    expr = cp_convert (promoted_type, expr);
+  return expr;
+}
+
 /* Take the address of an inline function without setting TREE_ADDRESSABLE
    or TREE_USED.  */
 
 tree
-inline_conversion (exp)
-     tree exp;
+inline_conversion (tree exp)
 {
   if (TREE_CODE (exp) == FUNCTION_DECL)
     exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
@@ -1734,9 +1462,7 @@ inline_conversion (exp)
    decay_conversion to one.  */
 
 int
-string_conv_p (totype, exp, warn)
-     tree totype, exp;
-     int warn;
+string_conv_p (tree totype, tree exp, int warn)
 {
   tree t;
 
@@ -1782,9 +1508,7 @@ string_conv_p (totype, exp, warn)
    get it there.  */
 
 static tree
-rationalize_conditional_expr (code, t)
-     enum tree_code code;
-     tree t;
+rationalize_conditional_expr (enum tree_code code, tree t)
 {
   /* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
      the first operand is always the one to be used if both operands
@@ -1795,7 +1519,8 @@ rationalize_conditional_expr (code, t)
        build_conditional_expr (build_x_binary_op ((TREE_CODE (t) == MIN_EXPR
                                                    ? LE_EXPR : GE_EXPR),
                                                   TREE_OPERAND (t, 0),
-                                                  TREE_OPERAND (t, 1)),
+                                                  TREE_OPERAND (t, 1),
+                                                  /*overloaded_p=*/NULL),
                            build_unary_op (code, TREE_OPERAND (t, 0), 0),
                            build_unary_op (code, TREE_OPERAND (t, 1), 0));
     }
@@ -1811,9 +1536,8 @@ rationalize_conditional_expr (code, t)
    anonymous unions can nest, we must also search all anonymous unions
    that are directly reachable.  */
 
-static tree
-lookup_anon_field (t, type)
-     tree t, type;
+tree
+lookup_anon_field (tree t, tree type)
 {
   tree field;
 
@@ -1877,7 +1601,8 @@ build_class_member_access_expr (tree object, tree member,
      The type of the first expression shall be "class object" (of a
      complete type).  */
   object_type = TREE_TYPE (object);
-  if (!complete_type_or_else (object_type, object))
+  if (!currently_open_class (object_type) 
+      && !complete_type_or_else (object_type, object))
     return error_mark_node;
   if (!CLASS_TYPE_P (object_type))
     {
@@ -1907,7 +1632,10 @@ build_class_member_access_expr (tree object, tree member,
     member_scope = TYPE_CONTEXT (member_scope);
   if (!member_scope || !DERIVED_FROM_P (member_scope, object_type))
     {
-      error ("`%D' is not a member of `%T'", member, object_type);
+      if (TREE_CODE (member) == FIELD_DECL)
+        error ("invalid use of nonstatic data member '%E'", member);
+      else
+        error ("`%D' is not a member of `%T'", member, object_type);
       return error_mark_node;
     }
 
@@ -1976,7 +1704,8 @@ build_class_member_access_expr (tree object, tree member,
         give the right answer.  Note that we complain whether or not they
         actually used the offsetof macro, since there's no way to know at this
         point.  So we just give a warning, instead of a pedwarn.  */
-      if (null_object_p && CLASSTYPE_NON_POD_P (object_type))
+      if (null_object_p && warn_invalid_offsetof
+         && CLASSTYPE_NON_POD_P (object_type))
        {
          warning ("invalid access to non-static data member `%D' of NULL object", 
                   member);
@@ -2023,7 +1752,8 @@ build_class_member_access_expr (tree object, tree member,
          member_type = cp_build_qualified_type (member_type, type_quals);
        }
 
-      result = fold (build (COMPONENT_REF, member_type, object, member));
+      result = fold (build (COMPONENT_REF, member_type, object, member,
+                           NULL_TREE));
 
       /* Mark the expression const or volatile, as appropriate.  Even
         though we've dealt with the type above, we still have to mark the
@@ -2050,7 +1780,7 @@ build_class_member_access_expr (tree object, tree member,
        type = unknown_type_node;
       /* Note that we do not convert OBJECT to the BASELINK_BINFO
         base.  That will happen when the function is called.  */
-      result = build (COMPONENT_REF, type, object, member);
+      result = build (COMPONENT_REF, type, object, member, NULL_TREE);
     }
   else if (TREE_CODE (member) == CONST_DECL)
     {
@@ -2085,6 +1815,7 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
 {
   tree object_type = TREE_TYPE (object);
   tree dtor_type = TREE_OPERAND (dtor_name, 0);
+  tree expr;
 
   if (scope && !check_dtor_name (scope, dtor_name))
     {
@@ -2092,17 +1823,20 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
             scope, dtor_type);
       return error_mark_node;
     }
-  if (!same_type_p (dtor_type, TYPE_MAIN_VARIANT (object_type)))
+  if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
     {
-      error ("destructor name `%T' does not match type `%T' of expression",
-            dtor_type, object_type);
+      error ("the type being destroyed is `%T', but the destructor refers to `%T'",
+            TYPE_MAIN_VARIANT (object_type), dtor_type);
       return error_mark_node;
     }
-  if (!TYPE_HAS_DESTRUCTOR (object_type))
+  if (!TYPE_HAS_DESTRUCTOR (dtor_type))
     return build (PSEUDO_DTOR_EXPR, void_type_node, object, scope,
                  dtor_type);
-  return lookup_member (object_type, complete_dtor_identifier,
+  expr = lookup_member (dtor_type, complete_dtor_identifier,
                        /*protect=*/1, /*want_type=*/false);
+  expr = (adjust_result_of_qualified_name_lookup
+         (expr, dtor_type, object_type));
+  return expr;
 }
 
 /* This function is called by the parser to process a class member
@@ -2116,20 +1850,39 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
 tree
 finish_class_member_access_expr (tree object, tree name)
 {
+  tree expr;
   tree object_type;
   tree member;
   tree access_path = NULL_TREE;
+  tree orig_object = object;
+  tree orig_name = name;
 
   if (object == error_mark_node || name == error_mark_node)
     return error_mark_node;
 
+  object_type = TREE_TYPE (object);
+
   if (processing_template_decl)
-    return build_min_nt (COMPONENT_REF, object, name);
+    {
+      if (/* If OBJECT_TYPE is dependent, so is OBJECT.NAME.  */
+         dependent_type_p (object_type)
+         /* If NAME is just an IDENTIFIER_NODE, then the expression
+            is dependent.  */
+         || TREE_CODE (object) == IDENTIFIER_NODE
+         /* If NAME is "f<args>", where either 'f' or 'args' is
+            dependent, then the expression is dependent.  */
+         || (TREE_CODE (name) == TEMPLATE_ID_EXPR
+             && dependent_template_id_p (TREE_OPERAND (name, 0),
+                                         TREE_OPERAND (name, 1)))
+         /* If NAME is "T::X" where "T" is dependent, then the
+            expression is dependent.  */
+         || (TREE_CODE (name) == SCOPE_REF
+             && TYPE_P (TREE_OPERAND (name, 0))
+             && dependent_type_p (TREE_OPERAND (name, 0))))
+       return build_min_nt (COMPONENT_REF, object, name, NULL_TREE);
+      object = build_non_dependent_expr (object);
+    }
   
-  if (TREE_CODE (object) == OFFSET_REF)
-    object = resolve_offset_ref (object);
-
-  object_type = TREE_TYPE (object);
   if (TREE_CODE (object_type) == REFERENCE_TYPE)
     {
       object = convert_from_reference (object);
@@ -2140,7 +1893,8 @@ finish_class_member_access_expr (tree object, tree name)
 
      The type of the first expression shall be "class object" (of a
      complete type).  */
-  if (!complete_type_or_else (object_type, object))
+  if (!currently_open_class (object_type) 
+      && !complete_type_or_else (object_type, object))
     return error_mark_node;
   if (!CLASS_TYPE_P (object_type))
     {
@@ -2161,18 +1915,22 @@ finish_class_member_access_expr (tree object, tree name)
     {
       bool is_template_id = false;
       tree template_args = NULL_TREE;
+      tree scope;
 
       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
        {
          is_template_id = true;
          template_args = TREE_OPERAND (name, 1);
          name = TREE_OPERAND (name, 0);
+
+         if (TREE_CODE (name) == OVERLOAD)
+           name = DECL_NAME (get_first_fn (name));
+         else if (DECL_P (name))
+           name = DECL_NAME (name);
        }
 
       if (TREE_CODE (name) == SCOPE_REF)
        {
-         tree scope;
-
          /* A qualified name.  The qualifying class or namespace `S' has
             already been looked up; it is either a TYPE or a
             NAMESPACE_DECL.  The member name is either an IDENTIFIER_NODE
@@ -2197,59 +1955,42 @@ finish_class_member_access_expr (tree object, tree name)
 
          /* Find the base of OBJECT_TYPE corresponding to SCOPE.  */
          access_path = lookup_base (object_type, scope, ba_check, NULL);
-         if (!access_path || access_path == error_mark_node)
+         if (access_path == error_mark_node)
            return error_mark_node;
-
-         if (TREE_CODE (name) == BIT_NOT_EXPR)
-           member = lookup_destructor (object, scope, name);
-         else
+         if (!access_path)
            {
-             /* Look up the member.  */
-             member = lookup_member (access_path, name, /*protect=*/1, 
-                                     /*want_type=*/false);
-             if (member == NULL_TREE)
-               {
-                 error ("'%D' has no member named '%E'", object_type, name);
-                 return error_mark_node;
-               }
-             if (member == error_mark_node)
-               return error_mark_node;
+             error ("`%T' is not a base of `%T'", scope, object_type);
+             return error_mark_node;
            }
        }
-      else if (TREE_CODE (name) == BIT_NOT_EXPR)
-       member = lookup_destructor (object, /*scope=*/NULL_TREE, name);
-      else if (TREE_CODE (name) == IDENTIFIER_NODE)
+      else
        {
-         /* An unqualified name.  */
-         member = lookup_member (object_type, name, /*protect=*/1, 
+         scope = NULL_TREE;
+         access_path = object_type;
+       }
+
+      if (TREE_CODE (name) == BIT_NOT_EXPR)
+       member = lookup_destructor (object, scope, name);
+      else
+       {
+         /* Look up the member.  */
+         member = lookup_member (access_path, name, /*protect=*/1, 
                                  /*want_type=*/false);
          if (member == NULL_TREE)
            {
              error ("'%D' has no member named '%E'", object_type, name);
              return error_mark_node;
            }
-         else if (member == error_mark_node)
+         if (member == error_mark_node)
            return error_mark_node;
        }
-      else
-       {
-         /* The YACC parser sometimes gives us things that are not names.
-            These always indicate errors.  The recursive-descent parser
-            does not do this, so this code can go away once that parser
-            replaces the YACC parser.  */
-         error ("invalid use of `%D'", name);
-         return error_mark_node;
-       }
       
       if (is_template_id)
        {
          tree template = member;
          
          if (BASELINK_P (template))
-           BASELINK_FUNCTIONS (template) 
-             = build_nt (TEMPLATE_ID_EXPR,
-                         BASELINK_FUNCTIONS (template),
-                         template_args);
+           template = lookup_template_function (template, template_args);
          else
            {
              error ("`%D' is not a member template function", name);
@@ -2261,8 +2002,12 @@ finish_class_member_access_expr (tree object, tree name)
   if (TREE_DEPRECATED (member))
     warn_deprecated_use (member);
 
-  return build_class_member_access_expr (object, member, access_path,
+  expr = build_class_member_access_expr (object, member, access_path,
                                         /*preserve_reference=*/false);
+  if (processing_template_decl && expr != error_mark_node)
+    return build_min_non_dep (COMPONENT_REF, expr,
+                             orig_object, orig_name, NULL_TREE);
+  return expr;
 }
 
 /* Return an expression for the MEMBER_NAME field in the internal
@@ -2289,7 +2034,7 @@ build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
                          /*want_type=*/false);
   member_type = cp_build_qualified_type (TREE_TYPE (member),
                                         cp_type_quals (ptrmem_type));
-  return fold (build (COMPONENT_REF, member_type, ptrmem, member));
+  return fold (build (COMPONENT_REF, member_type, ptrmem, member, NULL_TREE));
 }
 
 /* Given an expression PTR for a pointer, return an expression
@@ -2300,28 +2045,33 @@ build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
    Must also handle REFERENCE_TYPEs for C++.  */
 
 tree
-build_x_indirect_ref (ptr, errorstring)
-     tree ptr;
-     const char *errorstring;
+build_x_indirect_ref (tree expr, const char *errorstring)
 {
+  tree orig_expr = expr;
   tree rval;
 
   if (processing_template_decl)
-    return build_min_nt (INDIRECT_REF, ptr);
+    {
+      if (type_dependent_expression_p (expr))
+       return build_min_nt (INDIRECT_REF, expr);
+      expr = build_non_dependent_expr (expr);
+    }
 
-  rval = build_new_op (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE,
-                      NULL_TREE);
-  if (rval)
+  rval = build_new_op (INDIRECT_REF, LOOKUP_NORMAL, expr, NULL_TREE,
+                      NULL_TREE, /*overloaded_p=*/NULL);
+  if (!rval)
+    rval = build_indirect_ref (expr, errorstring);
+
+  if (processing_template_decl && rval != error_mark_node)
+    return build_min_non_dep (INDIRECT_REF, rval, orig_expr);
+  else
     return rval;
-  return build_indirect_ref (ptr, errorstring);
 }
 
 tree
-build_indirect_ref (ptr, errorstring)
-     tree ptr;
-     const char *errorstring;
+build_indirect_ref (tree ptr, const char *errorstring)
 {
-  register tree pointer, type;
+  tree pointer, type;
 
   if (ptr == error_mark_node)
     return error_mark_node;
@@ -2330,7 +2080,7 @@ build_indirect_ref (ptr, errorstring)
     return current_class_ref;
 
   pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE
-            ? ptr : default_conversion (ptr));
+            ? ptr : decay_conversion (ptr));
   type = TREE_TYPE (pointer);
 
   if (TYPE_PTR_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
@@ -2373,7 +2123,7 @@ build_indirect_ref (ptr, errorstring)
     }
   /* `pointer' won't be an error_mark_node if we were given a
      pointer to member, so it's cool to check for this here.  */
-  else if (TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
+  else if (TYPE_PTR_TO_MEMBER_P (type))
     error ("invalid use of `%s' on pointer to member", errorstring);
   else if (pointer != error_mark_node)
     {
@@ -2399,8 +2149,7 @@ build_indirect_ref (ptr, errorstring)
    will inherit the type of the array, which will be some pointer type.  */
 
 tree
-build_array_ref (array, idx)
-     tree array, idx;
+build_array_ref (tree array, tree idx)
 {
   if (idx == 0)
     {
@@ -2433,8 +2182,7 @@ build_array_ref (array, idx)
       break;
     }
 
-  if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
-      && TREE_CODE (array) != INDIRECT_REF)
+  if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
     {
       tree rval, type;
 
@@ -2448,15 +2196,19 @@ build_array_ref (array, idx)
          && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node)
        warning ("array subscript has type `char'");
 
-      /* Apply default promotions *after* noticing character types.  */
-      idx = default_conversion (idx);
-
-      if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE)
+      if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
        {
          error ("array subscript is not an integer");
          return error_mark_node;
        }
 
+      /* Apply integral promotions *after* noticing character types.
+        (It is unclear why we do these promotions -- the standard
+        does not say that we should.  In fact, the natual thing would
+        seem to be to convert IDX to ptrdiff_t; we're performing
+        pointer arithmetic.)  */
+      idx = perform_integral_promotions (idx);
+
       /* An array that is indexed by a non-constant
         cannot be stored in a register; we must be able to do
         address arithmetic on its address.
@@ -2475,8 +2227,8 @@ build_array_ref (array, idx)
         would get a crash in store_bit_field/extract_bit_field when trying
         to access a non-existent part of the register.  */
       if (TREE_CODE (idx) == INTEGER_CST
-         && TYPE_VALUES (TREE_TYPE (array))
-         && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array))))
+         && TYPE_DOMAIN (TREE_TYPE (array))
+         && ! int_fits_type_p (idx, TYPE_DOMAIN (TREE_TYPE (array))))
        {
          if (!cxx_mark_addressable (array))
            return error_mark_node;
@@ -2498,7 +2250,7 @@ build_array_ref (array, idx)
        }
 
       type = TREE_TYPE (TREE_TYPE (array));
-      rval = build (ARRAY_REF, type, array, idx);
+      rval = build (ARRAY_REF, type, array, idx, NULL_TREE, NULL_TREE);
       /* Array ref is const/volatile if the array elements are
         or if the array is..  */
       TREE_READONLY (rval)
@@ -2552,9 +2304,7 @@ build_array_ref (array, idx)
    later has the right member.  */
 
 tree
-get_member_function_from_ptrfunc (instance_ptrptr, function)
-     tree *instance_ptrptr;
-     tree function;
+get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function)
 {
   if (TREE_CODE (function) == OFFSET_REF)
     function = TREE_OPERAND (function, 1);
@@ -2634,6 +2384,7 @@ get_member_function_from_ptrfunc (instance_ptrptr, function)
       e2 = fold (build (PLUS_EXPR, TREE_TYPE (vtbl), vtbl, idx));
       e2 = build_indirect_ref (e2, NULL);
       TREE_CONSTANT (e2) = 1;
+      TREE_INVARIANT (e2) = 1;
 
       /* When using function descriptors, the address of the
         vtable entry is treated as a function pointer.  */
@@ -2656,13 +2407,11 @@ get_member_function_from_ptrfunc (instance_ptrptr, function)
 }
 
 tree
-build_function_call (function, params)
-     tree function, params;
+build_function_call (tree function, tree params)
 {
-  register tree fntype, fndecl;
-  register tree coerced_params;
-  tree result;
-  tree name = NULL_TREE, assembler_name = NULL_TREE;
+  tree fntype, fndecl;
+  tree coerced_params;
+  tree name = NULL_TREE;
   int is_method;
   tree original = function;
 
@@ -2675,7 +2424,6 @@ build_function_call (function, params)
   if (TREE_CODE (function) == FUNCTION_DECL)
     {
       name = DECL_NAME (function);
-      assembler_name = DECL_ASSEMBLER_NAME (function);
 
       mark_used (function);
       fndecl = function;
@@ -2738,23 +2486,9 @@ build_function_call (function, params)
   /* Check for errors in format strings.  */
 
   if (warn_format)
-    check_function_format (NULL, TYPE_ATTRIBUTES (fntype), coerced_params);
-
-  /* Recognize certain built-in functions so we can make tree-codes
-     other than CALL_EXPR.  We do this when it enables fold-const.c
-     to do something useful.  */
+    check_function_format (TYPE_ATTRIBUTES (fntype), coerced_params);
 
-  if (TREE_CODE (function) == ADDR_EXPR
-      && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
-      && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
-    {
-      result = expand_tree_builtin (TREE_OPERAND (function, 0),
-                                   params, coerced_params);
-      if (result)
-       return result;
-    }
-
-  return build_cxx_call (function, params, coerced_params);
+  return build_cxx_call (function, coerced_params);
 }
 \f
 /* Convert the actual parameter expressions in the list VALUES
@@ -2775,12 +2509,10 @@ build_function_call (function, params)
    default arguments, if such were specified.  Do so here.  */
 
 tree
-convert_arguments (typelist, values, fndecl, flags)
-     tree typelist, values, fndecl;
-     int flags;
+convert_arguments (tree typelist, tree values, tree fndecl, int flags)
 {
-  register tree typetail, valtail;
-  register tree result = NULL_TREE;
+  tree typetail, valtail;
+  tree result = NULL_TREE;
   const char *called_thing = 0;
   int i = 0;
 
@@ -2805,8 +2537,8 @@ convert_arguments (typelist, values, fndecl, flags)
        valtail;
        valtail = TREE_CHAIN (valtail), i++)
     {
-      register tree type = typetail ? TREE_VALUE (typetail) : 0;
-      register tree val = TREE_VALUE (valtail);
+      tree type = typetail ? TREE_VALUE (typetail) : 0;
+      tree val = TREE_VALUE (valtail);
 
       if (val == error_mark_node)
        return error_mark_node;
@@ -2828,9 +2560,6 @@ convert_arguments (typelist, values, fndecl, flags)
          break;
        }
 
-      if (TREE_CODE (val) == OFFSET_REF)
-       val = resolve_offset_ref (val);
-
       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
         Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
       if (TREE_CODE (val) == NOP_EXPR
@@ -2843,7 +2572,7 @@ convert_arguments (typelist, values, fndecl, flags)
          if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
              || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
              || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
-           val = default_conversion (val);
+           val = decay_conversion (val);
        }
 
       if (val == error_mark_node)
@@ -2856,8 +2585,12 @@ convert_arguments (typelist, values, fndecl, flags)
 
          if (!COMPLETE_TYPE_P (complete_type (type)))
            {
-             error ("parameter type of called function is incomplete");
-             parmval = val;
+             if (fndecl)
+               error ("parameter %P of `%D' has incomplete type `%T'",
+                      i, fndecl, type);
+             else
+               error ("parameter %P has incomplete type `%T'", i, type);
+             parmval = error_mark_node;
            }
          else
            {
@@ -2895,7 +2628,7 @@ convert_arguments (typelist, values, fndecl, flags)
 
   if (typetail != 0 && typetail != void_list_node)
     {
-      /* See if there are default arguments that can be used */
+      /* See if there are default arguments that can be used */
       if (TREE_PURPOSE (typetail) 
          && TREE_CODE (TREE_PURPOSE (typetail)) != DEFAULT_ARG)
        {
@@ -2937,193 +2670,37 @@ convert_arguments (typelist, values, fndecl, flags)
    conversions on the operands.  CODE is the kind of expression to build.  */
 
 tree
-build_x_binary_op (code, arg1, arg2)
-     enum tree_code code;
-     tree arg1, arg2;
-{
-  if (processing_template_decl)
-    return build_min_nt (code, arg1, arg2);
-
-  return build_new_op (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
-}
-
-#if 0
-
-tree
-build_template_expr (enum tree_code code, tree op0, tree op1, tree op2)
-{
-  tree type;
-
-  /* If any of the operands is erroneous the result is erroneous too.  */
-  if (error_operand_p (op0)
-      || (op1 && error_operand_p (op1))
-      || (op2 && error_operand_p (op2)))
-    return error_mark_node;
-      
-  if (dependent_type_p (TREE_TYPE (op0))
-      || (op1 && dependent_type_p (TREE_TYPE (op1)))
-      || (op2 && dependent_type_p (TREE_TYPE (op2))))
-    /* If at least one operand has a dependent type, we cannot
-       determine the type of the expression until instantiation time.  */
-    type = NULL_TREE;
-  else
-    {
-      struct z_candidate *cand;
-      tree op0_type;
-      tree op1_type;
-      tree op2_type;
-
-      /* None of the operands is dependent, so we can compute the type
-        of the expression at this point.  We must compute the type so
-        that in things like:
-
-          template <int I>
-          void f() { S<sizeof(I + 3)> s; ... }
-
-        we can tell that the type of "s" is non-dependent.
-
-        If we're processing a template argument, we do not want to
-        actually change the operands in any way.  Adding conversions,
-        performing constant folding, etc., would all change mangled
-        names.  For example, in:
-        
-          template <int I>
-          void f(S<sizeof(3 + 4 + I)>);
-        
-        we need to determine that "3 + 4 + I" has type "int", without
-        actually turning the expression into "7 + I".  */
-      cand = find_overloaded_op (code, op0, op1, op2);
-      if (cand) 
-       /* If an overloaded operator was found, the expression will
-          have the type returned by the function.  */
-       type = non_reference (TREE_TYPE (cand->fn));
-      else
-       {
-         /* There is no overloaded operator so we can just use the
-            default rules for determining the type of the operand.  */
-         op0_type = TREE_TYPE (op0);
-         op1_type = op1 ? TREE_TYPE (op1) : NULL_TREE;
-         op2_type = op2 ? TREE_TYPE (op2) : NULL_TREE;
-         type = NULL_TREE;
-
-         switch (code)
-           {
-           case MODIFY_EXPR:
-             /* [expr.ass]
-
-                The result of the assignment operation is the value
-                stored in the left operand.  */
-             type = op0_type;
-             break;
-           case COMPONENT_REF:
-             /* Implement this case.  */
-             break;
-           case POSTINCREMENT_EXPR:
-           case POSTDECREMENT_EXPR:
-             /* [expr.post.incr]
-
-                The type of the result is the cv-unqualified version
-                of the type of the operand.  */
-             type = TYPE_MAIN_VARIANT (op0_type);
-             break;
-           case PREINCREMENT_EXPR:
-           case PREDECREMENT_EXPR:
-             /* [expr.pre.incr]
-
-                The value is the new value of the operand.  */
-             type = op0_type;
-             break;
-           case INDIRECT_REF:
-             /* [expr.unary.op]
-
-                If the type of the expression is "pointer to T", the
-                type of the result is "T".  */
-             type = TREE_TYPE (op0_type);
-             break;
-           case ADDR_EXPR:
-             /* [expr.unary.op]
-
-                If the type of the expression is "T", the type of the
-                result is "pointer to T".  */
-             /* FIXME: Handle the pointer-to-member case.  */
-             break;
-           case MEMBER_REF:
-             /* FIXME: Implement this case.  */
-             break;
-           case LSHIFT_EXPR:
-           case RSHIFT_EXPR:
-             /* [expr.shift]
-
-                The type of the result is that of the promoted left
-                operand.  */
-             break;
-           case PLUS_EXPR:
-           case MINUS_EXPR:
-             /* FIXME: Be careful of special pointer-arithmetic
-                cases.  */
-             /* Fall through. */
-           case MAX_EXPR:
-           case MIN_EXPR:
-             /* These are GNU extensions; the result type is computed
-                as it would be for other arithmetic operators.  */
-             /* Fall through. */
-           case BIT_AND_EXPR:
-           case BIT_XOR_EXPR:
-           case BIT_IOR_EXPR:
-           case MULT_EXPR:
-           case TRUNC_DIV_EXPR:
-           case TRUNC_MOD_EXPR:
-             /* [expr.bit.and], [expr.xor], [expr.or], [expr.mul]
-
-                The usual arithmetic conversions are performed on the
-                operands and determine the type of the result.  */
-             /* FIXME: Check that this is possible.  */
-             type = type_after_usual_arithmetic_conversions (t1, t2);
-             break;
-           case GT_EXPR:
-           case LT_EXPR:
-           case GE_EXPR:
-           case LE_EXPR:
-           case EQ_EXPR:
-           case NE_EXPR:
-             /* [expr.rel]
-
-                The type of the result is bool.  */
-             type = boolean_type_node;
-             break;
-           case TRUTH_ANDIF_EXPR:
-           case TRUTH_ORIF_EXPR:
-             /* [expr.log.and], [expr.log.org]
-                
-                The result is a bool.  */
-             type = boolean_type_node;
-             break;
-           case COND_EXPR:
-             /* FIXME: Handle special rules for conditioanl
-                expressions.  */
-             break;
-           case COMPOUND_EXPR:
-             type = op1_type;
-             break;
-           default:
-             abort ();
-           }
-         /* If the type of the expression could not be determined,
-            something is wrong.  */
-         if (!type)
-           abort ();
-         /* If the type is erroneous, the expression is erroneous
-            too.  */
-         if (type == error_mark_node)
-           return error_mark_node;
-       }
+build_x_binary_op (enum tree_code code, tree arg1, tree arg2, 
+                  bool *overloaded_p)
+{
+  tree orig_arg1;
+  tree orig_arg2;
+  tree expr;
+
+  orig_arg1 = arg1;
+  orig_arg2 = arg2;
+
+  if (processing_template_decl)
+    {
+      if (type_dependent_expression_p (arg1)
+         || type_dependent_expression_p (arg2))
+       return build_min_nt (code, arg1, arg2);
+      arg1 = build_non_dependent_expr (arg1);
+      arg2 = build_non_dependent_expr (arg2);
     }
+
+  if (code == DOTSTAR_EXPR)
+    expr = build_m_component_ref (arg1, arg2);
+  else
+    expr = build_new_op (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE, 
+                        overloaded_p);
+
+  if (processing_template_decl && expr != error_mark_node)
+    return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
   
-  return build_min (code, type, op0, op1, op2, NULL_TREE);
+  return expr;
 }
 
-#endif
-
 /* Build a binary-operation expression without default conversions.
    CODE is the kind of expression to build.
    This function differs from `build' in several ways:
@@ -3143,23 +2720,21 @@ build_template_expr (enum tree_code code, tree op0, tree op1, tree op2)
    multiple inheritance, and deal with pointer to member functions.  */
 
 tree
-build_binary_op (code, orig_op0, orig_op1, convert_p)
-     enum tree_code code;
-     tree orig_op0, orig_op1;
-     int convert_p ATTRIBUTE_UNUSED;
+build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
+                int convert_p ATTRIBUTE_UNUSED)
 {
   tree op0, op1;
-  register enum tree_code code0, code1;
+  enum tree_code code0, code1;
   tree type0, type1;
 
   /* Expression code to give to the expression when it is built.
      Normally this is CODE, which is what the caller asked for,
      but in some special cases we change it.  */
-  register enum tree_code resultcode = code;
+  enum tree_code resultcode = code;
 
   /* Data type in which the computation is to be performed.
      In the simplest cases this is the common type of the arguments.  */
-  register tree result_type = NULL;
+  tree result_type = NULL;
 
   /* Nonzero means operands have already been type-converted
      in whatever way is necessary.
@@ -3271,7 +2846,8 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
       /* Subtraction of two similar pointers.
         We must subtract them as integers, then divide by object size.  */
       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
-         && comp_target_types (type0, type1, 1))
+         && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
+                                                       TREE_TYPE (type1)))
        return pointer_diff (op0, op1, common_type (type0, type1));
       /* Handle pointer minus int.  Just like pointer plus int.  */
       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
@@ -3308,7 +2884,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
               point, so we have to dig out the original type to find out if
               it was unsigned.  */
            shorten = ((TREE_CODE (op0) == NOP_EXPR
-                       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
+                       && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
                       || (TREE_CODE (op1) == INTEGER_CST
                           && ! integer_all_onesp (op1)));
 
@@ -3317,7 +2893,6 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
       break;
 
     case BIT_AND_EXPR:
-    case BIT_ANDTC_EXPR:
     case BIT_IOR_EXPR:
     case BIT_XOR_EXPR:
       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
@@ -3338,7 +2913,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
             quotient can't be represented in the computation mode.  We shorten
             only if unsigned or if dividing by something we know != -1.  */
          shorten = ((TREE_CODE (op0) == NOP_EXPR
-                     && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
+                     && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
                     || (TREE_CODE (op1) == INTEGER_CST
                         && ! integer_all_onesp (op1)));
          common = 1;
@@ -3433,12 +3008,15 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
          && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
              || code1 == COMPLEX_TYPE))
        short_compare = 1;
-      else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
+      else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
+              || (TYPE_PTRMEM_P (type0) && TYPE_PTRMEM_P (type1)))
        result_type = composite_pointer_type (type0, type1, op0, op1,
                                              "comparison");
-      else if (code0 == POINTER_TYPE && null_ptr_cst_p (op1))
+      else if ((code0 == POINTER_TYPE || TYPE_PTRMEM_P (type0))
+              && null_ptr_cst_p (op1))
        result_type = type0;
-      else if (code1 == POINTER_TYPE && null_ptr_cst_p (op0))
+      else if ((code1 == POINTER_TYPE || TYPE_PTRMEM_P (type1))
+              && null_ptr_cst_p (op0))
        result_type = type1;
       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
        {
@@ -3594,7 +3172,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
          tree arg0 = get_narrower (op0, &unsigned0);
          tree arg1 = get_narrower (op1, &unsigned1);
          /* UNS is 1 if the operation to be done is an unsigned one.  */
-         int uns = TREE_UNSIGNED (result_type);
+         int uns = TYPE_UNSIGNED (result_type);
          tree type;
 
          final_type = result_type;
@@ -3603,9 +3181,9 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
             but it *requires* conversion to FINAL_TYPE.  */
 
          if (op0 == arg0 && TREE_TYPE (op0) != final_type)
-           unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
+           unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
          if (op1 == arg1 && TREE_TYPE (op1) != final_type)
-           unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
+           unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
 
          /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
 
@@ -3657,7 +3235,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
          final_type = result_type;
 
          if (arg0 == op0 && final_type == TREE_TYPE (op0))
-           unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
+           unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
 
          if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
              /* We can shorten only if the shift count is less than the
@@ -3670,7 +3248,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
                 ones made by sign-extension and bring in zeros.
                 We can't optimize that case at all, but in most machines
                 it never happens because available widths are 2**N.  */
-             && (!TREE_UNSIGNED (final_type)
+             && (!TYPE_UNSIGNED (final_type)
                  || unsigned_arg
                  || (((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0)))
                      <= TYPE_PRECISION (result_type))))
@@ -3707,10 +3285,13 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
        }
 
       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
-         && warn_sign_compare)
+         && warn_sign_compare
+         /* Do not warn until the template is instantiated; we cannot
+            bound the ranges of the arguments until that point.  */
+         && !processing_template_decl)
        {
-         int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
-         int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
+         int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0));
+         int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1));
 
          int unsignedp0, unsignedp1;
          tree primop0 = get_narrower (op0, &unsignedp0);
@@ -3734,7 +3315,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
          /* Do not warn if the comparison is being done in a signed type,
             since the signed type will only be chosen if it can represent
             all the values of the unsigned type.  */
-         if (! TREE_UNSIGNED (result_type))
+         if (!TYPE_UNSIGNED (result_type))
            /* OK */;
          /* Do not warn if both operands are unsigned.  */
          else if (op0_signed == op1_signed)
@@ -3862,15 +3443,10 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
     build_type = result_type;
 
   {
-    register tree result = build (resultcode, build_type, op0, op1);
-    register tree folded;
-
-    folded = fold (result);
-    if (folded == result)
-      TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
+    tree result = fold (build (resultcode, build_type, op0, op1));
     if (final_type != 0)
-      return cp_convert (final_type, folded);
-    return folded;
+      result = cp_convert (final_type, result);
+    return result;
   }
 }
 \f
@@ -3878,9 +3454,7 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
    of pointer PTROP and integer INTOP.  */
 
 static tree
-cp_pointer_int_sum (resultcode, ptrop, intop)
-     enum tree_code resultcode;
-     register tree ptrop, intop;
+cp_pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop)
 {
   tree res_type = TREE_TYPE (ptrop);
 
@@ -3898,11 +3472,9 @@ cp_pointer_int_sum (resultcode, ptrop, intop)
    The resulting tree has type int.  */
 
 static tree
-pointer_diff (op0, op1, ptrtype)
-     register tree op0, op1;
-     register tree ptrtype;
+pointer_diff (tree op0, tree op1, tree ptrtype)
 {
-  register tree result, folded;
+  tree result;
   tree restype = ptrdiff_type_node;
   tree target_type = TREE_TYPE (ptrtype);
 
@@ -3917,8 +3489,6 @@ pointer_diff (op0, op1, ptrtype)
        pedwarn ("ISO C++ forbids using pointer to a function in subtraction");
       if (TREE_CODE (target_type) == METHOD_TYPE)
        pedwarn ("ISO C++ forbids using pointer to a method in subtraction");
-      if (TREE_CODE (target_type) == OFFSET_TYPE)
-       pedwarn ("ISO C++ forbids using pointer to a member in subtraction");
     }
 
   /* First do the subtraction as integers;
@@ -3932,21 +3502,14 @@ pointer_diff (op0, op1, ptrtype)
   if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
     error ("invalid use of a pointer to an incomplete type in pointer arithmetic");
 
-  op1 = ((TREE_CODE (target_type) == VOID_TYPE
-         || TREE_CODE (target_type) == FUNCTION_TYPE
-         || TREE_CODE (target_type) == METHOD_TYPE
-         || TREE_CODE (target_type) == OFFSET_TYPE)
-        ? integer_one_node
-        : size_in_bytes (target_type));
+  op1 = (TYPE_PTROB_P (ptrtype) 
+        ? size_in_bytes (target_type)
+        : integer_one_node);
 
   /* Do the division.  */
 
   result = build (EXACT_DIV_EXPR, restype, op0, cp_convert (restype, op1));
-
-  folded = fold (result);
-  if (folded == result)
-    TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
-  return folded;
+  return fold (result);
 }
 \f
 /* Construct and perhaps optimize a tree representation
@@ -3954,34 +3517,39 @@ pointer_diff (op0, op1, ptrtype)
    and XARG is the operand.  */
 
 tree
-build_x_unary_op (code, xarg)
-     enum tree_code code;
-     tree xarg;
+build_x_unary_op (enum tree_code code, tree xarg)
 {
+  tree orig_expr = xarg;
   tree exp;
   int ptrmem = 0;
   
   if (processing_template_decl)
-    return build_min_nt (code, xarg, NULL_TREE);
+    {
+      if (type_dependent_expression_p (xarg))
+       return build_min_nt (code, xarg, NULL_TREE);
+      xarg = build_non_dependent_expr (xarg);
+    }
+
+  exp = NULL_TREE;
+
+  /* [expr.unary.op] says:
+
+       The address of an object of incomplete type can be taken.
 
-  /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
-     error message.  */
+     (And is just the ordinary address operator, not an overloaded
+     "operator &".)  However, if the type is a template
+     specialization, we must complete the type at this point so that
+     an overloaded "operator &" will be available if required.  */
   if (code == ADDR_EXPR
       && TREE_CODE (xarg) != TEMPLATE_ID_EXPR
-      && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg)))
-          && !COMPLETE_TYPE_P (TREE_TYPE (xarg)))
+      && ((CLASS_TYPE_P (TREE_TYPE (xarg))
+          && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (xarg))))
          || (TREE_CODE (xarg) == OFFSET_REF)))
-    /* don't look for a function */;
+    /* Don't look for a function.  */;
   else
-    {
-      tree rval;
-
-      rval = build_new_op (code, LOOKUP_NORMAL, xarg,
-                          NULL_TREE, NULL_TREE);
-      if (rval || code != ADDR_EXPR)
-       return rval;
-    }
-  if (code == ADDR_EXPR)
+    exp = build_new_op (code, LOOKUP_NORMAL, xarg, NULL_TREE, NULL_TREE,
+                       /*overloaded_p=*/NULL);
+  if (!exp && code == ADDR_EXPR)
     {
       /*  A pointer to member-function can be formed only by saying
          &X::mf.  */
@@ -4015,16 +3583,18 @@ build_x_unary_op (code, xarg)
                            TREE_OPERAND (xarg, 0),
                            ovl_cons (TREE_OPERAND (xarg, 1), NULL_TREE));
              PTRMEM_OK_P (xarg) = ptrmem;
-           }
-             
+           }         
         }
       else if (TREE_CODE (xarg) == TARGET_EXPR)
        warning ("taking address of temporary");
+      exp = build_unary_op (ADDR_EXPR, xarg, 0);
+      if (TREE_CODE (exp) == ADDR_EXPR)
+       PTRMEM_OK_P (exp) = ptrmem;
     }
-  exp = build_unary_op (code, xarg, 0);
-  if (TREE_CODE (exp) == ADDR_EXPR)
-    PTRMEM_OK_P (exp) = ptrmem;
 
+  if (processing_template_decl && exp != error_mark_node)
+    return build_min_non_dep (code, exp, orig_expr,
+                             /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
   return exp;
 }
 
@@ -4033,8 +3603,7 @@ build_x_unary_op (code, xarg)
    -1.  */
 
 tree
-cp_truthvalue_conversion (expr)
-     tree expr;
+cp_truthvalue_conversion (tree expr)
 {
   tree type = TREE_TYPE (expr);
   if (TYPE_PTRMEM_P (type))
@@ -4046,14 +3615,11 @@ cp_truthvalue_conversion (expr)
 /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  */
    
 tree
-condition_conversion (expr)
-     tree expr;
+condition_conversion (tree expr)
 {
   tree t;
   if (processing_template_decl)
     return expr;
-  if (TREE_CODE (expr) == OFFSET_REF)
-    expr = resolve_offset_ref (expr);
   t = perform_implicit_conversion (boolean_type_node, expr);
   t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t));
   return t;
@@ -4071,11 +3637,7 @@ build_address (tree t)
   if (error_operand_p (t) || !cxx_mark_addressable (t))
     return error_mark_node;
 
-  addr = build1 (ADDR_EXPR, 
-                build_pointer_type (TREE_TYPE (t)),
-                t);
-  if (staticp (t))
-    TREE_CONSTANT (addr) = 1;
+  addr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (t)), t);
 
   return addr;
 }
@@ -4085,16 +3647,9 @@ build_address (tree t)
 tree
 build_nop (tree type, tree expr)
 {
-  tree nop;
-
   if (type == error_mark_node || error_operand_p (expr))
     return expr;
-    
-  nop = build1 (NOP_EXPR, type, expr);
-  if (TREE_CONSTANT (expr))
-    TREE_CONSTANT (nop) = 1;
-  
-  return nop;
+  return build1 (NOP_EXPR, type, expr);
 }
 
 /* C++: Must handle pointers to members.
@@ -4107,14 +3662,11 @@ build_nop (tree type, tree expr)
    (such as from short to int).  */
 
 tree
-build_unary_op (code, xarg, noconvert)
-     enum tree_code code;
-     tree xarg;
-     int noconvert;
+build_unary_op (enum tree_code code, tree xarg, int noconvert)
 {
   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
-  register tree arg = xarg;
-  register tree argtype = 0;
+  tree arg = xarg;
+  tree argtype = 0;
   const char *errstring = NULL;
   tree val;
 
@@ -4133,17 +3685,16 @@ build_unary_op (code, xarg, noconvert)
       else
        {
          if (!noconvert)
-          arg = default_conversion (arg);
+           arg = default_conversion (arg);
          arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg);
-         TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
        }
       break;
 
     case NEGATE_EXPR:
       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
        errstring = "wrong type argument to unary minus";
-      else if (!noconvert)
-       arg = default_conversion (arg);
+      else if (!noconvert && CP_INTEGRAL_TYPE_P (TREE_TYPE (arg)))
+       arg = perform_integral_promotions (arg);
       break;
 
     case BIT_NOT_EXPR:
@@ -4157,7 +3708,7 @@ build_unary_op (code, xarg, noconvert)
                                                   arg, true)))
        errstring = "wrong type argument to bit-complement";
       else if (!noconvert)
-       arg = default_conversion (arg);
+       arg = perform_integral_promotions (arg);
       break;
 
     case ABS_EXPR:
@@ -4176,7 +3727,7 @@ build_unary_op (code, xarg, noconvert)
       break;
 
     case TRUTH_NOT_EXPR:
-      arg = cp_convert (boolean_type_node, arg);
+      arg = perform_implicit_conversion (boolean_type_node, arg);
       val = invert_truthvalue (arg);
       if (arg != error_mark_node)
        return val;
@@ -4252,7 +3803,7 @@ build_unary_op (code, xarg, noconvert)
                        0);
 
       {
-       register tree inc;
+       tree inc;
        tree result_type = TREE_TYPE (arg);
 
        arg = get_unwidened (arg, 0);
@@ -4268,7 +3819,6 @@ build_unary_op (code, xarg, noconvert)
 
        if (TREE_CODE (argtype) == POINTER_TYPE)
          {
-           enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype));
            tree type = complete_type (TREE_TYPE (argtype));
            
            if (!COMPLETE_OR_VOID_TYPE_P (type))
@@ -4277,8 +3827,7 @@ build_unary_op (code, xarg, noconvert)
                          || code == POSTINCREMENT_EXPR)
                         ? "increment" : "decrement"), TREE_TYPE (argtype));
            else if ((pedantic || warn_pointer_arith)
-                    && (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE
-                        || tmp == VOID_TYPE || tmp == OFFSET_TYPE))
+                    && !TYPE_PTROB_P (argtype))
              pedwarn ("ISO C++ forbids %sing a pointer of type `%T'",
                          ((code == PREINCREMENT_EXPR
                            || code == POSTINCREMENT_EXPR)
@@ -4319,7 +3868,7 @@ build_unary_op (code, xarg, noconvert)
              compound = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
 
              /* Eliminate warning about unused result of + or -.  */
-             TREE_NO_UNUSED_WARNING (compound) = 1;
+             TREE_NO_WARNING (compound) = 1;
              return compound;
            }
 
@@ -4341,13 +3890,7 @@ build_unary_op (code, xarg, noconvert)
                error ("invalid use of `--' on bool variable `%D'", arg);
                return error_mark_node;
              }
-#if 0
-           /* This will only work if someone can convince Kenner to accept
-              my patch to expand_increment. (jason)  */
-           val = build (code, TREE_TYPE (arg), arg, inc);
-#else
            val = boolean_increment (code, arg);
-#endif
          }
        else
          val = build (code, TREE_TYPE (arg), arg, inc);
@@ -4361,12 +3904,14 @@ build_unary_op (code, xarg, noconvert)
         regardless of NOCONVERT.  */
 
       argtype = lvalue_type (arg);
+
+      if (TREE_CODE (arg) == OFFSET_REF)
+       goto offset_ref;
+
       if (TREE_CODE (argtype) == REFERENCE_TYPE)
        {
-         arg = build1
-           (CONVERT_EXPR,
-            build_pointer_type (TREE_TYPE (argtype)), arg);
-         TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
+         tree type = build_pointer_type (TREE_TYPE (argtype));
+         arg = build1 (CONVERT_EXPR, type, arg);
          return arg;
        }
       else if (pedantic && DECL_MAIN_P (arg))
@@ -4384,10 +3929,8 @@ build_unary_op (code, xarg, noconvert)
          arg = TREE_OPERAND (arg, 0);
          if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
            {
-             arg = build1
-               (CONVERT_EXPR,
-                build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
-             TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
+             tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg)));
+             arg = build1 (CONVERT_EXPR, type, arg);
            }
          else if (lvalue_p (arg))
            /* Don't let this be an lvalue.  */
@@ -4395,8 +3938,12 @@ build_unary_op (code, xarg, noconvert)
          return arg;
        }
 
-      /* For &x[y], return x+y */
-      if (TREE_CODE (arg) == ARRAY_REF)
+      /* For &x[y], return x+y.  But, in a template, ARG may be an
+        ARRAY_REF representing a non-dependent expression.  In that
+        case, there may be an overloaded "operator []" that will be
+        chosen at instantiation time; we must not try to optimize
+        here.  */
+      if (TREE_CODE (arg) == ARRAY_REF && !processing_template_decl)
        {
          if (!cxx_mark_addressable (TREE_OPERAND (arg, 0)))
            return error_mark_node;
@@ -4452,9 +3999,10 @@ build_unary_op (code, xarg, noconvert)
                         "  Say `&%T::%D'",
                         base, name);
            }
-         arg = build_offset_ref (base, name);
+         arg = build_offset_ref (base, name, /*address_p=*/true);
         }
-        
+
+    offset_ref:        
       if (type_unknown_p (arg))
        return build1 (ADDR_EXPR, unknown_type_node, arg);
        
@@ -4476,7 +4024,11 @@ build_unary_op (code, xarg, noconvert)
          if (! lvalue_p (arg) && pedantic)
            pedwarn ("ISO C++ forbids taking the address of a cast to a non-lvalue expression");
          break;
-         
+
+       case OVERLOAD:
+         arg = OVL_CURRENT (arg);
+         break;
+
        default:
          break;
        }
@@ -4490,7 +4042,7 @@ build_unary_op (code, xarg, noconvert)
         is an error.  */
       else if (TREE_CODE (argtype) != FUNCTION_TYPE
               && TREE_CODE (argtype) != METHOD_TYPE
-              && !non_cast_lvalue_or_else (arg, "unary `&'"))
+              && !lvalue_or_else (arg, "unary `&'"))
        return error_mark_node;
 
       if (argtype != error_mark_node)
@@ -4499,12 +4051,28 @@ build_unary_op (code, xarg, noconvert)
       {
        tree addr;
 
-       if (TREE_CODE (arg) == COMPONENT_REF
-           && TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
-         arg = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
-
-       if (TREE_CODE (arg) != COMPONENT_REF)
+       if (TREE_CODE (arg) != COMPONENT_REF
+           /* Inside a template, we are processing a non-dependent
+              expression so we can just form an ADDR_EXPR with the
+              correct type.  */
+           || processing_template_decl)
          addr = build_address (arg);
+       else if (TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
+         {
+           tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
+
+           /* We can only get here with a single static member
+              function.  */
+           my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL
+                               && DECL_STATIC_FUNCTION_P (fn),
+                               20030906);
+           mark_used (fn);
+           addr = build_address (fn);
+           if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
+             /* Do not lose object's side effects.  */
+             addr = build (COMPOUND_EXPR, TREE_TYPE (addr),
+                           TREE_OPERAND (arg, 0), addr);
+         }
        else if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
          {
            error ("attempt to take address of bit-field structure member `%D'",
@@ -4523,8 +4091,7 @@ build_unary_op (code, xarg, noconvert)
                                      ba_check, NULL);
            
            rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
-           rval = build1 (NOP_EXPR, argtype, rval);
-           TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
+           rval = build_nop (argtype, rval);
            addr = fold (build (PLUS_EXPR, argtype, rval,
                                cp_convert (argtype, byte_position (field))));
          }
@@ -4561,9 +4128,7 @@ build_unary_op (code, xarg, noconvert)
    If ARG is not a kind of expression we can handle, return zero.  */
    
 tree
-unary_complex_lvalue (code, arg)
-     enum tree_code code;
-     tree arg;
+unary_complex_lvalue (enum tree_code code, tree arg)
 {
   /* Handle (a, b) used as an "lvalue".  */
   if (TREE_CODE (arg) == COMPOUND_EXPR)
@@ -4603,17 +4168,14 @@ unary_complex_lvalue (code, arg)
     {
       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
       arg = build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result);
-      TREE_NO_UNUSED_WARNING (arg) = 1;
+      TREE_NO_WARNING (arg) = 1;
       return arg;
     }
 
   if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
       || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
-      || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE)
+      || TREE_CODE (arg) == OFFSET_REF)
     {
-      /* The representation of something of type OFFSET_TYPE
-        is really the representation of a pointer to it.
-        Here give the representation its true type.  */
       tree t;
 
       my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313);
@@ -4644,15 +4206,7 @@ unary_complex_lvalue (code, arg)
              return error_mark_node;
            }
          if (!PTRMEM_OK_P (arg))
-           {
-             /* This cannot form a pointer to method, so we must
-                resolve the offset ref, and take the address of the
-                result.  For instance,
-                       &(C::m)       */
-             arg = resolve_offset_ref (arg);
-
-             return build_unary_op (code, arg, 0);
-           }
+           return build_unary_op (code, arg, 0);
          
          if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
            {
@@ -4660,7 +4214,8 @@ unary_complex_lvalue (code, arg)
              return error_mark_node;
            }
 
-         type = build_ptrmem_type (DECL_FIELD_CONTEXT (t), TREE_TYPE (t));
+         type = build_ptrmem_type (context_for_name_lookup (t), 
+                                   TREE_TYPE (t));
          t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1));
          return t;
        }
@@ -4700,10 +4255,9 @@ unary_complex_lvalue (code, arg)
    C++: we do not allow `current_class_ptr' to be addressable.  */
 
 bool
-cxx_mark_addressable (exp)
-     tree exp;
+cxx_mark_addressable (tree exp)
 {
-  register tree x = exp;
+  tree x = exp;
 
   while (1)
     switch (TREE_CODE (x))
@@ -4720,10 +4274,10 @@ cxx_mark_addressable (exp)
        if (x == current_class_ptr)
          {
             error ("cannot take the address of `this', which is an rvalue expression");
-           TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
+           TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
            return true;
          }
-       /* FALLTHRU */
+       /* Fall through.  */
 
       case VAR_DECL:
        /* Caller should not be trying to mark initialized
@@ -4732,7 +4286,7 @@ cxx_mark_addressable (exp)
                            || DECL_IN_AGGR_P (x) == 0
                            || TREE_STATIC (x)
                            || DECL_EXTERNAL (x), 314);
-       /* FALLTHRU */
+       /* Fall through.  */
 
       case CONST_DECL:
       case RESULT_DECL:
@@ -4746,7 +4300,6 @@ cxx_mark_addressable (exp)
 
       case FUNCTION_DECL:
        TREE_ADDRESSABLE (x) = 1;
-       TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
        return true;
 
       case CONSTRUCTOR:
@@ -4766,115 +4319,141 @@ cxx_mark_addressable (exp)
 /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
 
 tree
-build_x_conditional_expr (ifexp, op1, op2)
-     tree ifexp, op1, op2;
+build_x_conditional_expr (tree ifexp, tree op1, tree op2)
 {
-  if (processing_template_decl)
-    return build_min_nt (COND_EXPR, ifexp, op1, op2);
+  tree orig_ifexp = ifexp;
+  tree orig_op1 = op1;
+  tree orig_op2 = op2;
+  tree expr;
 
-  return build_conditional_expr (ifexp, op1, op2);
+  if (processing_template_decl)
+    {
+      /* The standard says that the expression is type-dependent if
+        IFEXP is type-dependent, even though the eventual type of the
+        expression doesn't dependent on IFEXP.  */
+      if (type_dependent_expression_p (ifexp)
+         /* As a GNU extension, the middle operand may be omitted.  */
+         || (op1 && type_dependent_expression_p (op1))
+         || type_dependent_expression_p (op2))
+       return build_min_nt (COND_EXPR, ifexp, op1, op2);
+      ifexp = build_non_dependent_expr (ifexp);
+      if (op1)
+       op1 = build_non_dependent_expr (op1);
+      op2 = build_non_dependent_expr (op2);
+    }
+
+  expr = build_conditional_expr (ifexp, op1, op2);
+  if (processing_template_decl && expr != error_mark_node)
+    return build_min_non_dep (COND_EXPR, expr, 
+                             orig_ifexp, orig_op1, orig_op2);
+  return expr;
 }
 \f
-/* Handle overloading of the ',' operator when needed.  Otherwise,
-   this function just builds an expression list.  */
+/* Given a list of expressions, return a compound expression
+   that performs them all and returns the value of the last of them.  */
+
+tree build_x_compound_expr_from_list (tree list, const char *msg)
+{
+  tree expr = TREE_VALUE (list);
+  
+  if (TREE_CHAIN (list))
+    {
+      if (msg)
+       pedwarn ("%s expression list treated as compound expression", msg);
+
+      for (list = TREE_CHAIN (list); list; list = TREE_CHAIN (list))
+       expr = build_x_compound_expr (expr, TREE_VALUE (list));
+    }
+  
+  return expr;
+}
+
+/* Handle overloading of the ',' operator when needed.  */
 
 tree
-build_x_compound_expr (list)
-     tree list;
+build_x_compound_expr (tree op1, tree op2)
 {
-  tree rest = TREE_CHAIN (list);
   tree result;
+  tree orig_op1 = op1;
+  tree orig_op2 = op2;
 
   if (processing_template_decl)
-    return build_min_nt (COMPOUND_EXPR, list, NULL_TREE);
+    {
+      if (type_dependent_expression_p (op1)
+         || type_dependent_expression_p (op2))
+       return build_min_nt (COMPOUND_EXPR, op1, op2);
+      op1 = build_non_dependent_expr (op1);
+      op2 = build_non_dependent_expr (op2);
+    }
 
-  if (rest == NULL_TREE)
-    return build_compound_expr (list);
+  result = build_new_op (COMPOUND_EXPR, LOOKUP_NORMAL, op1, op2, NULL_TREE,
+                        /*overloaded_p=*/NULL);
+  if (!result)
+    result = build_compound_expr (op1, op2);
 
-  result = build_new_op (COMPOUND_EXPR, LOOKUP_NORMAL,
-                        TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE);
-  if (result)
-    return build_x_compound_expr (tree_cons (NULL_TREE, result,
-                                                 TREE_CHAIN (rest)));
-
-  if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
-    {
-      /* FIXME: This test should be in the implicit cast to void of the LHS.  */
-      /* the left-hand operand of a comma expression is like an expression
-         statement: we should warn if it doesn't have any side-effects,
-         unless it was explicitly cast to (void).  */
-      if (warn_unused_value
-           && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
-                && VOID_TYPE_P (TREE_TYPE (TREE_VALUE(list)))))
-        warning("left-hand operand of comma expression has no effect");
-    }
-#if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
-  else if (warn_unused_value)
-    warn_if_unused_value (TREE_VALUE(list));
-#endif
-
-  return build_compound_expr
-    (tree_cons (NULL_TREE, TREE_VALUE (list),
-                    build_tree_list (NULL_TREE,
-                                     build_x_compound_expr (rest))));
+  if (processing_template_decl && result != error_mark_node)
+    return build_min_non_dep (COMPOUND_EXPR, result, orig_op1, orig_op2);
+  
+  return result;
 }
 
-/* Given a list of expressions, return a compound expression
-   that performs them all and returns the value of the last of them.  */
+/* Build a compound expression.  */
 
 tree
-build_compound_expr (list)
-     tree list;
+build_compound_expr (tree lhs, tree rhs)
 {
-  register tree rest;
-  tree first;
-
-  TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
-
-  if (TREE_CHAIN (list) == 0)
+  lhs = decl_constant_value (lhs);
+  lhs = convert_to_void (lhs, "left-hand operand of comma");
+  
+  if (lhs == error_mark_node || rhs == error_mark_node)
+    return error_mark_node;
+  
+  if (TREE_CODE (rhs) == TARGET_EXPR)
     {
-      /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
-        Strip such NOP_EXPRs, since LIST is used in non-lvalue context.  */
-      if (TREE_CODE (list) == NOP_EXPR
-         && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
-       list = TREE_OPERAND (list, 0);
-       
-      return TREE_VALUE (list);
+      /* If the rhs is a TARGET_EXPR, then build the compound
+         expression inside the target_expr's initializer. This
+        helps the compiler to eliminate unnecessary temporaries.  */
+      tree init = TREE_OPERAND (rhs, 1);
+      
+      init = build (COMPOUND_EXPR, TREE_TYPE (init), lhs, init);
+      TREE_OPERAND (rhs, 1) = init;
+      
+      return rhs;
     }
-
-  first = TREE_VALUE (list);
-  first = convert_to_void (first, "left-hand operand of comma");
-  if (first == error_mark_node)
-    return error_mark_node;
   
-  rest = build_compound_expr (TREE_CHAIN (list));
-  if (rest == error_mark_node)
-    return error_mark_node;
+  return build (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
+}
 
-  /* When pedantic, a compound expression cannot be a constant expression.  */
-  if (! TREE_SIDE_EFFECTS (first) && ! pedantic)
-    return rest;
+/* Issue an error message if casting from SRC_TYPE to DEST_TYPE casts
+   away constness.  DESCRIPTION explains what operation is taking
+   place.  */
 
-  return build (COMPOUND_EXPR, TREE_TYPE (rest), first, rest);
+static void
+check_for_casting_away_constness (tree src_type, tree dest_type,
+                                 const char *description)
+{
+  if (casts_away_constness (src_type, dest_type))
+    error ("%s from type `%T' to type `%T' casts away constness",
+          description, src_type, dest_type);
 }
 
+/* Return an expression representing static_cast<TYPE>(EXPR).  */
+
 tree
-build_static_cast (type, expr)
-   tree type, expr;
+build_static_cast (tree type, tree expr)
 {
   tree intype;
-  int ok;
+  tree result;
 
   if (type == error_mark_node || expr == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (expr) == OFFSET_REF)
-    expr = resolve_offset_ref (expr);
-
   if (processing_template_decl)
     {
-      tree t = build_min (STATIC_CAST_EXPR, type, expr); 
-      return t;
+      expr = build_min (STATIC_CAST_EXPR, type, expr);
+      /* We don't know if it will or will not have side effects.  */
+      TREE_SIDE_EFFECTS (expr) = 1;
+      return expr;
     }
 
   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
@@ -4884,108 +4463,198 @@ build_static_cast (type, expr)
       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
     expr = TREE_OPERAND (expr, 0);
 
-  if (TREE_CODE (type) == VOID_TYPE)
-    {
-      expr = convert_to_void (expr, /*implicit=*/NULL);
-      return expr;
+  intype = TREE_TYPE (expr);
+
+  /* [expr.static.cast]
+
+     An lvalue of type "cv1 B", where B is a class type, can be cast
+     to type "reference to cv2 D", where D is a class derived (clause
+     _class.derived_) from B, if a valid standard conversion from
+     "pointer to D" to "pointer to B" exists (_conv.ptr_), cv2 is the
+     same cv-qualification as, or greater cv-qualification than, cv1,
+     and B is not a virtual base class of D.  */
+  /* We check this case before checking the validity of "TYPE t =
+     EXPR;" below because for this case:
+
+       struct B {};
+       struct D : public B { D(const B&); };
+       extern B& b;
+       void f() { static_cast<const D&>(b); }
+
+     we want to avoid constructing a new D.  The standard is not
+     completely clear about this issue, but our interpretation is
+     consistent with other compilers.  */
+  if (TREE_CODE (type) == REFERENCE_TYPE
+      && CLASS_TYPE_P (TREE_TYPE (type))
+      && CLASS_TYPE_P (intype)
+      && real_lvalue_p (expr)
+      && DERIVED_FROM_P (intype, TREE_TYPE (type))
+      && can_convert (build_pointer_type (TYPE_MAIN_VARIANT (intype)),
+                     build_pointer_type (TYPE_MAIN_VARIANT 
+                                         (TREE_TYPE (type))))
+      && at_least_as_qualified_p (TREE_TYPE (type), intype))
+    {
+      /* There is a standard conversion from "D*" to "B*" even if "B"
+        is ambiguous or inaccessible.  Therefore, we ask lookup_base
+        to check these conditions.  */
+      tree base = lookup_base (TREE_TYPE (type), intype, ba_check, NULL);
+
+      /* Convert from "B*" to "D*".  This function will check that "B"
+        is not a virtual base of "D".  */
+      expr = build_base_path (MINUS_EXPR, build_address (expr), 
+                             base, /*nonnull=*/false);
+      /* Convert the pointer to a reference -- but then remember that
+        there are no expressions with reference type in C++.  */
+      return convert_from_reference (build_nop (type, expr));
     }
 
-  if (TREE_CODE (type) == REFERENCE_TYPE)
-    return (convert_from_reference
-           (convert_to_reference (type, expr, CONV_STATIC|CONV_IMPLICIT,
-                                  LOOKUP_COMPLAIN, NULL_TREE)));
+  /* [expr.static.cast]
 
-  if (IS_AGGR_TYPE (type))
-    return build_cplus_new (type, (build_special_member_call
-                                  (NULL_TREE, complete_ctor_identifier, 
-                                   build_tree_list (NULL_TREE, expr),
-                                   TYPE_BINFO (type), LOOKUP_NORMAL)));
+     An expression e can be explicitly converted to a type T using a
+     static_cast of the form static_cast<T>(e) if the declaration T
+     t(e);" is well-formed, for some invented temporary variable
+     t.  */
+  result = perform_direct_initialization_if_possible (type, expr);
+  if (result)
+    {
+      result = convert_from_reference (result);
+      /* [expr.static.cast]
+
+         If T is a reference type, the result is an lvalue; otherwise,
+        the result is an rvalue.  */
+      if (TREE_CODE (type) != REFERENCE_TYPE
+         && real_lvalue_p (result))
+       result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
+      return result;
+    }
   
-  intype = TREE_TYPE (expr);
+  /* [expr.static.cast]
+
+     Any expression can be explicitly converted to type cv void.  */
+  if (TREE_CODE (type) == VOID_TYPE)
+    return convert_to_void (expr, /*implicit=*/NULL);
+
+  /* [expr.static.cast]
 
-  /* FIXME handle casting to array type.  */
+     The inverse of any standard conversion sequence (clause _conv_),
+     other than the lvalue-to-rvalue (_conv.lval_), array-to-pointer
+     (_conv.array_), function-to-pointer (_conv.func_), and boolean
+     (_conv.bool_) conversions, can be performed explicitly using
+     static_cast subject to the restriction that the explicit
+     conversion does not cast away constness (_expr.const.cast_), and
+     the following additional rules for specific cases:  */
+  /* For reference, the conversions not excluded are: integral
+     promotions, floating point promotion, integral conversions,
+     floating point conversions, floating-integral conversions,
+     pointer conversions, and pointer to member conversions.  */
+  if ((ARITHMETIC_TYPE_P (type) && ARITHMETIC_TYPE_P (intype))
+      /* DR 128
+
+         A value of integral _or enumeration_ type can be explicitly
+        converted to an enumeration type.  */
+      || (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
+         && INTEGRAL_OR_ENUMERATION_TYPE_P (intype)))
+    /* Really, build_c_cast should defer to this function rather
+       than the other way around.  */
+    return build_c_cast (type, expr);
+  
+  if (TYPE_PTR_P (type) && TYPE_PTR_P (intype)
+      && CLASS_TYPE_P (TREE_TYPE (type))
+      && CLASS_TYPE_P (TREE_TYPE (intype))
+      && can_convert (build_pointer_type (TYPE_MAIN_VARIANT 
+                                         (TREE_TYPE (intype))), 
+                     build_pointer_type (TYPE_MAIN_VARIANT 
+                                         (TREE_TYPE (type)))))
+    {
+      tree base;
 
-  ok = 0;
-  if (IS_AGGR_TYPE (intype)
-      ? can_convert_arg (type, intype, expr)
-      : can_convert_arg (strip_all_pointer_quals (type),
-                         strip_all_pointer_quals (intype), expr))
-    /* This is a standard conversion.  */
-    ok = 1;
-  else if (TYPE_PTROB_P (type) && TYPE_PTROB_P (intype))
+      check_for_casting_away_constness (intype, type, "static_cast");
+      base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype), ba_check, 
+                         NULL);
+      return build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false);
+    }
+  
+  if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
+      || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
     {
-      /* They're pointers to objects. They must be aggregates that
-         are related non-virtually.  */
-      base_kind kind;
-      
-      if (IS_AGGR_TYPE (TREE_TYPE (type)) && IS_AGGR_TYPE (TREE_TYPE (intype))
-         && lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
-                         ba_ignore | ba_quiet, &kind)
-         && kind != bk_via_virtual)
-       ok = 1;
-    }
-  else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
-    {
-      /* They're pointers to members. The pointed to objects must be
-        the same (ignoring CV qualifiers), and the containing classes
-        must be related non-virtually.  */
-      base_kind kind;
-      
-      if (same_type_p
-         (strip_all_pointer_quals (TREE_TYPE (TREE_TYPE (type))),
-          strip_all_pointer_quals (TREE_TYPE (TREE_TYPE (intype))))
-         && (lookup_base (TYPE_OFFSET_BASETYPE (TREE_TYPE (intype)),
-                          TYPE_OFFSET_BASETYPE (TREE_TYPE (type)),
-                          ba_ignore | ba_quiet, &kind))
-         && kind != bk_via_virtual)
-       ok = 1;
-    }
-  else if (TREE_CODE (intype) != BOOLEAN_TYPE
-          && TREE_CODE (type) != ARRAY_TYPE
-          && TREE_CODE (type) != FUNCTION_TYPE
-          && can_convert (intype, strip_all_pointer_quals (type)))
-    ok = 1;
-  else if (TREE_CODE (intype) == ENUMERAL_TYPE
-           && TREE_CODE (type) == ENUMERAL_TYPE)
-    /* DR 128: "A value of integral _or enumeration_ type can be explicitly
-       converted to an enumeration type."
-       The integral to enumeration will be accepted by the previous clause.
-       We need to explicitly check for enumeration to enumeration.  */
-    ok = 1;
+      tree c1;
+      tree c2;
+      tree t1;
+      tree t2;
+
+      c1 = TYPE_PTRMEM_CLASS_TYPE (intype);
+      c2 = TYPE_PTRMEM_CLASS_TYPE (type);
 
+      if (TYPE_PTRMEM_P (type))
+       {
+         t1 = (build_ptrmem_type 
+               (c1,
+                TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (intype))));
+         t2 = (build_ptrmem_type 
+               (c2,
+                TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (type))));
+       }
+      else
+       {
+         t1 = intype;
+         t2 = type;
+       }
+      if (can_convert (t1, t2))
+       {
+         check_for_casting_away_constness (intype, type, "static_cast");
+         if (TYPE_PTRMEM_P (type))
+           {
+             tree delta;
+
+             if (TREE_CODE (expr) == PTRMEM_CST)
+               expr = cplus_expand_constant (expr);
+             delta = get_delta_difference (c1, c2, /*force=*/1);
+             if (!integer_zerop (delta))
+               expr = cp_build_binary_op (PLUS_EXPR, 
+                                          build_nop (ptrdiff_type_node, expr),
+                                          delta);
+             return build_nop (type, expr);
+           }
+         else
+           return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 
+                                    /*force=*/1);
+       }
+    }
+    
   /* [expr.static.cast]
 
-     The static_cast operator shall not be used to cast away
-     constness.  */
-  if (ok && casts_away_constness (intype, type))
+     An rvalue of type "pointer to cv void" can be explicitly
+     converted to a pointer to object type.  A value of type pointer
+     to object converted to "pointer to cv void" and back to the
+     original pointer type will have its original value.  */
+  if (TREE_CODE (intype) == POINTER_TYPE 
+      && VOID_TYPE_P (TREE_TYPE (intype))
+      && TYPE_PTROB_P (type))
     {
-      error ("static_cast from type `%T' to type `%T' casts away constness",
-               intype, type);
-      return error_mark_node;
+      check_for_casting_away_constness (intype, type, "static_cast");
+      return build_nop (type, expr);
     }
 
-  if (ok)
-    return build_c_cast (type, expr);
-
   error ("invalid static_cast from type `%T' to type `%T'", intype, type);
   return error_mark_node;
 }
 
 tree
-build_reinterpret_cast (type, expr)
-   tree type, expr;
+build_reinterpret_cast (tree type, tree expr)
 {
   tree intype;
 
   if (type == error_mark_node || expr == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (expr) == OFFSET_REF)
-    expr = resolve_offset_ref (expr);
-
   if (processing_template_decl)
     {
       tree t = build_min (REINTERPRET_CAST_EXPR, type, expr);
+      
+      if (!TREE_SIDE_EFFECTS (t)
+         && type_dependent_expression_p (expr))
+       /* There might turn out to be side effects inside expr.  */
+       TREE_SIDE_EFFECTS (t) = 1;
       return t;
     }
 
@@ -5038,10 +4707,7 @@ build_reinterpret_cast (type, expr)
   else if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
           || (TYPE_PTROBV_P (type) && TYPE_PTROBV_P (intype)))
     {
-      if (! comp_ptr_ttypes_reinterpret (TREE_TYPE (type), TREE_TYPE (intype)))
-       pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
-                   intype, type);
-
+      check_for_casting_away_constness (intype, type, "reinterpret_cast");
       expr = decl_constant_value (expr);
       return fold (build1 (NOP_EXPR, type, expr));
     }
@@ -5063,24 +4729,25 @@ build_reinterpret_cast (type, expr)
 }
 
 tree
-build_const_cast (type, expr)
-   tree type, expr;
+build_const_cast (tree type, tree expr)
 {
   tree intype;
 
   if (type == error_mark_node || expr == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (expr) == OFFSET_REF)
-    expr = resolve_offset_ref (expr);
-
   if (processing_template_decl)
     {
       tree t = build_min (CONST_CAST_EXPR, type, expr);
+      
+      if (!TREE_SIDE_EFFECTS (t)
+         && type_dependent_expression_p (expr))
+       /* There might turn out to be side effects inside expr.  */
+       TREE_SIDE_EFFECTS (t) = 1;
       return t;
     }
 
-  if (!POINTER_TYPE_P (type))
+  if (!POINTER_TYPE_P (type) && !TYPE_PTRMEM_P (type))
     error ("invalid use of const_cast with type `%T', which is not a pointer, reference, nor a pointer-to-data-member type", type);
   else if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     {
@@ -5118,8 +4785,9 @@ build_const_cast (type, expr)
          return convert_from_reference (expr);
        }
     }
-  else if (TREE_CODE (type) == POINTER_TYPE
-          && TREE_CODE (intype) == POINTER_TYPE
+  else if (((TREE_CODE (type) == POINTER_TYPE
+            && TREE_CODE (intype) == POINTER_TYPE)
+           || (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype)))
           && comp_ptr_ttypes_const (TREE_TYPE (type), TREE_TYPE (intype)))
     return cp_convert (type, expr);
 
@@ -5133,10 +4801,9 @@ build_const_cast (type, expr)
    when doing the cast.  */
 
 tree
-build_c_cast (type, expr)
-     tree type, expr;
+build_c_cast (tree type, tree expr)
 {
-  register tree value = expr;
+  tree value = expr;
   tree otype;
 
   if (type == error_mark_node || expr == error_mark_node)
@@ -5146,6 +4813,8 @@ build_c_cast (type, expr)
     {
       tree t = build_min (CAST_EXPR, type,
                          tree_cons (NULL_TREE, value, NULL_TREE));
+      /* We don't know if it will or will not have side effects.  */
+      TREE_SIDE_EFFECTS (t) = 1;
       return t;
     }
 
@@ -5156,9 +4825,6 @@ build_c_cast (type, expr)
       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
     value = TREE_OPERAND (value, 0);
 
-  if (TREE_CODE (value) == OFFSET_REF)
-    value = resolve_offset_ref (value);
-
   if (TREE_CODE (type) == ARRAY_TYPE)
     {
       /* Allow casting from T1* to T2[] because Cfront allows it.
@@ -5190,6 +4856,10 @@ build_c_cast (type, expr)
       value = convert_to_void (value, /*implicit=*/NULL);
       return value;
     }
+
+  if (!complete_type_or_else (type, NULL_TREE))
+    return error_mark_node;
+
   /* Convert functions and arrays to pointers and
      convert references to their expanded types,
      but don't convert any other types.  If, however, we are
@@ -5212,7 +4882,7 @@ build_c_cast (type, expr)
                    && bound_pmf_p (value)))
          || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
          || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
-       value = default_conversion (value);
+       value = decay_conversion (value);
     }
   else if (TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
     /* However, even for class types, we still need to strip away
@@ -5234,11 +4904,11 @@ build_c_cast (type, expr)
                 otype, type);
 
   if (TREE_CODE (type) == INTEGER_TYPE
-      && TREE_CODE (otype) == POINTER_TYPE
+      && TYPE_PTR_P (otype)
       && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
     warning ("cast from pointer to integer of different size");
 
-  if (TREE_CODE (type) == POINTER_TYPE
+  if (TYPE_PTR_P (type)
       && TREE_CODE (otype) == INTEGER_TYPE
       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
       /* Don't warn about converting any constant.  */
@@ -5262,7 +4932,9 @@ build_c_cast (type, expr)
       if (TREE_CODE (value) == INTEGER_CST)
        {
          TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
-         TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
+
+         if (TREE_CODE_CLASS (TREE_CODE (ovalue)) == 'c')
+           TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
        }
     }
 
@@ -5296,16 +4968,13 @@ build_c_cast (type, expr)
    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.  */
 
 tree
-build_modify_expr (lhs, modifycode, rhs)
-     tree lhs;
-     enum tree_code modifycode;
-     tree rhs;
+build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
 {
-  register tree result;
+  tree result;
   tree newrhs = rhs;
   tree lhstype = TREE_TYPE (lhs);
   tree olhstype = lhstype;
-  tree olhs = lhs;
+  tree olhs = NULL_TREE;
 
   /* Avoid duplicate error messages from operands that had errors.  */
   if (lhs == error_mark_node || rhs == error_mark_node)
@@ -5314,7 +4983,7 @@ build_modify_expr (lhs, modifycode, rhs)
   /* Handle control structure constructs used as "lvalues".  */
   switch (TREE_CODE (lhs))
     {
-      /* Handle --foo = 5; as these are valid constructs in C++ */
+      /* Handle --foo = 5; as these are valid constructs in C++ */
     case PREDECREMENT_EXPR:
     case PREINCREMENT_EXPR:
       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
@@ -5336,6 +5005,10 @@ build_modify_expr (lhs, modifycode, rhs)
                    TREE_OPERAND (lhs, 0), newrhs);
 
     case MODIFY_EXPR:
+      if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
+       lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs),
+                    stabilize_reference (TREE_OPERAND (lhs, 0)),
+                    TREE_OPERAND (lhs, 1));
       newrhs = build_modify_expr (TREE_OPERAND (lhs, 0), modifycode, rhs);
       if (newrhs == error_mark_node)
        return error_mark_node;
@@ -5370,15 +5043,11 @@ build_modify_expr (lhs, modifycode, rhs)
          return cond;
        /* Make sure the code to compute the rhs comes out
           before the split.  */
-       return build (COMPOUND_EXPR, TREE_TYPE (lhs), preeval, cond);
+       if (preeval)
+         cond = build (COMPOUND_EXPR, TREE_TYPE (lhs), preeval, cond);
+       return cond;
       }
       
-    case OFFSET_REF:
-      lhs = resolve_offset_ref (lhs);
-      if (lhs == error_mark_node)
-       return error_mark_node;
-      olhstype = lhstype = TREE_TYPE (lhs);
-    
     default:
       break;
     }
@@ -5387,14 +5056,15 @@ build_modify_expr (lhs, modifycode, rhs)
     {
       if (TREE_CODE (rhs) == CONSTRUCTOR)
        {
-         my_friendly_assert (same_type_p (TREE_TYPE (rhs), lhstype),
-                             20011220);
+         if (! same_type_p (TREE_TYPE (rhs), lhstype))
+           /* Call convert to generate an error; see PR 11063.  */
+           rhs = convert (lhstype, rhs);
          result = build (INIT_EXPR, lhstype, lhs, rhs);
          TREE_SIDE_EFFECTS (result) = 1;
          return result;
        }
       else if (! IS_AGGR_TYPE (lhstype))
-       /* Do the default thing */;
+       /* Do the default thing */;
       else
        {
          result = build_special_member_call (lhs, complete_ctor_identifier,
@@ -5421,11 +5091,12 @@ build_modify_expr (lhs, modifycode, rhs)
        {
          /* `operator=' is not an inheritable operator.  */
          if (! IS_AGGR_TYPE (lhstype))
-           /* Do the default thing */;
+           /* Do the default thing */;
          else
            {
              result = build_new_op (MODIFY_EXPR, LOOKUP_NORMAL,
-                                    lhs, rhs, make_node (NOP_EXPR));
+                                    lhs, rhs, make_node (NOP_EXPR),
+                                    /*overloaded_p=*/NULL);
              if (result == NULL_TREE)
                return error_mark_node;
              return result;
@@ -5457,52 +5128,7 @@ build_modify_expr (lhs, modifycode, rhs)
                          20011220);
     }
 
-  /* Handle a cast used as an "lvalue".
-     We have already performed any binary operator using the value as cast.
-     Now convert the result to the cast type of the lhs,
-     and then true type of the lhs and store it there;
-     then convert result back to the cast type to be the value
-     of the assignment.  */
-
-  switch (TREE_CODE (lhs))
-    {
-    case NOP_EXPR:
-    case CONVERT_EXPR:
-    case FLOAT_EXPR:
-    case FIX_TRUNC_EXPR:
-    case FIX_FLOOR_EXPR:
-    case FIX_ROUND_EXPR:
-    case FIX_CEIL_EXPR:
-      {
-       tree inner_lhs = TREE_OPERAND (lhs, 0);
-       tree result;
-
-       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
-           || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE
-           || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE
-           || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE)
-         newrhs = default_conversion (newrhs);
-       
-       /* ISO C++ 5.4/1: The result is an lvalue if T is a reference
-          type, otherwise the result is an rvalue.  */
-       if (! lvalue_p (lhs))
-         pedwarn ("ISO C++ forbids cast to non-reference type used as lvalue");
-
-       result = build_modify_expr (inner_lhs, NOP_EXPR,
-                                   cp_convert (TREE_TYPE (inner_lhs),
-                                               cp_convert (lhstype, newrhs)));
-       if (result == error_mark_node)
-         return result;
-       return cp_convert (TREE_TYPE (lhs), result);
-      }
-
-    default:
-      break;
-    }
-
-  /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
-     Reject anything strange now.  */
-
+  /* The left-hand side must be an lvalue.  */
   if (!lvalue_or_else (lhs, "assignment"))
     return error_mark_node;
 
@@ -5536,19 +5162,20 @@ build_modify_expr (lhs, modifycode, rhs)
 
       if (lhstype != TREE_TYPE (lhs))
        {
+         /* Avoid warnings converting integral types back into enums for
+            enum bit fields.  */
+         if (TREE_CODE (lhstype) == INTEGER_TYPE
+             && TREE_CODE (olhstype) == ENUMERAL_TYPE)
+           {
+             if (TREE_SIDE_EFFECTS (lhs))
+               lhs = stabilize_reference (lhs);
+             olhs = lhs;
+           }
          lhs = copy_node (lhs);
          TREE_TYPE (lhs) = lhstype;
        }
     }
 
-  if (TREE_CODE (lhstype) != REFERENCE_TYPE)
-    {
-      if (TREE_SIDE_EFFECTS (lhs))
-       lhs = stabilize_reference (lhs);
-      if (TREE_SIDE_EFFECTS (newrhs))
-       newrhs = stabilize_reference (newrhs);
-    }
-
   /* Convert new value to destination type.  */
 
   if (TREE_CODE (lhstype) == ARRAY_TYPE)
@@ -5604,44 +5231,8 @@ build_modify_expr (lhs, modifycode, rhs)
   if (newrhs == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (newrhs) == COND_EXPR)
-    {
-      tree lhs1;
-      tree cond = TREE_OPERAND (newrhs, 0);
-
-      if (TREE_SIDE_EFFECTS (lhs))
-       cond = build_compound_expr (tree_cons
-                                   (NULL_TREE, lhs,
-                                    build_tree_list (NULL_TREE, cond)));
-
-      /* Cannot have two identical lhs on this one tree (result) as preexpand
-        calls will rip them out and fill in RTL for them, but when the
-        rtl is generated, the calls will only be in the first side of the
-        condition, not on both, or before the conditional jump! (mrs) */
-      lhs1 = break_out_calls (lhs);
-
-      if (lhs == lhs1)
-       /* If there's no change, the COND_EXPR behaves like any other rhs.  */
-       result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
-                       lhstype, lhs, newrhs);
-      else
-       {
-         tree result_type = TREE_TYPE (newrhs);
-         /* We have to convert each arm to the proper type because the
-            types may have been munged by constant folding.  */
-         result
-           = build (COND_EXPR, result_type, cond,
-                    build_modify_expr (lhs, modifycode,
-                                       cp_convert (result_type,
-                                                   TREE_OPERAND (newrhs, 1))),
-                    build_modify_expr (lhs1, modifycode,
-                                       cp_convert (result_type,
-                                                   TREE_OPERAND (newrhs, 2))));
-       }
-    }
-  else
-    result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
-                   lhstype, lhs, newrhs);
+  result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
+                 lhstype, lhs, newrhs);
 
   TREE_SIDE_EFFECTS (result) = 1;
 
@@ -5652,13 +5243,10 @@ build_modify_expr (lhs, modifycode, rhs)
 
   if (olhstype == TREE_TYPE (result))
     return result;
-  /* Avoid warnings converting integral types back into enums
-     for enum bit fields.  */
-  if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
-      && TREE_CODE (olhstype) == ENUMERAL_TYPE)
+  if (olhs)
     {
       result = build (COMPOUND_EXPR, olhstype, result, olhs);
-      TREE_NO_UNUSED_WARNING (result) = 1;
+      TREE_NO_WARNING (result) = 1;
       return result;
     }
   return convert_for_assignment (olhstype, result, "assignment",
@@ -5666,10 +5254,7 @@ build_modify_expr (lhs, modifycode, rhs)
 }
 
 tree
-build_x_modify_expr (lhs, modifycode, rhs)
-     tree lhs;
-     enum tree_code modifycode;
-     tree rhs;
+build_x_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
 {
   if (processing_template_decl)
     return build_min_nt (MODOP_EXPR, lhs,
@@ -5678,7 +5263,8 @@ build_x_modify_expr (lhs, modifycode, rhs)
   if (modifycode != NOP_EXPR)
     {
       tree rval = build_new_op (MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs,
-                               make_node (modifycode));
+                               make_node (modifycode),
+                               /*overloaded_p=*/NULL);
       if (rval)
        return rval;
     }
@@ -5687,8 +5273,9 @@ build_x_modify_expr (lhs, modifycode, rhs)
 
 \f
 /* Get difference in deltas for different pointer to member function
-   types.  Return integer_zero_node, if FROM cannot be converted to a
-   TO type.  If FORCE is true, then allow reverse conversions as well.
+   types.  Returns an integer constant of type PTRDIFF_TYPE_NODE.  If
+   the conversion is invalid, the constant is zero.  If FORCE is true,
+   then allow reverse conversions as well.
 
    Note that the naming of FROM and TO is kind of backwards; the return
    value is what we add to a TO in order to get a FROM.  They are named
@@ -5696,73 +5283,65 @@ build_x_modify_expr (lhs, modifycode, rhs)
    a pointer to member of FROM to a pointer to member of TO.  */
 
 static tree
-get_delta_difference (from, to, force)
-     tree from, to;
-     int force;
+get_delta_difference (tree from, tree to, int force)
 {
-  tree delta = integer_zero_node;
   tree binfo;
   tree virt_binfo;
   base_kind kind;
-  
+  tree result;
+
+  /* Assume no conversion is required.  */
+  result = integer_zero_node;
   binfo = lookup_base (to, from, ba_check, &kind);
   if (kind == bk_inaccessible || kind == bk_ambig)
-    {
-      error ("   in pointer to member function conversion");
-      return delta;
-    }
-  if (!binfo)
+    error ("   in pointer to member function conversion");
+  else if (!binfo)
     {
       if (!force)
        {
          error_not_base_type (from, to);
          error ("   in pointer to member conversion");
-         return delta;
        }
-      binfo = lookup_base (from, to, ba_check, &kind);
-      if (binfo == 0)
-       return delta;
-      virt_binfo = binfo_from_vbase (binfo);
-      
-      if (virt_binfo)
-        {
-          /* This is a reinterpret cast, we choose to do nothing.  */
-          warning ("pointer to member cast via virtual base `%T'",
-                  BINFO_TYPE (virt_binfo));
-          return delta;
-        }
-      delta = BINFO_OFFSET (binfo);
-      delta = cp_convert (ptrdiff_type_node, delta);
-      delta = cp_build_binary_op (MINUS_EXPR,
-                                integer_zero_node,
-                                delta);
-
-      return delta;
+      else
+       {
+         binfo = lookup_base (from, to, ba_check, &kind);
+         if (binfo)
+           {
+             virt_binfo = binfo_from_vbase (binfo);
+             if (virt_binfo)
+               /* This is a reinterpret cast, we choose to do nothing.  */
+               warning ("pointer to member cast via virtual base `%T'",
+                        BINFO_TYPE (virt_binfo));
+             else
+               result = size_diffop (size_zero_node, BINFO_OFFSET (binfo));
+           }
+       }
     }
-
-  virt_binfo = binfo_from_vbase (binfo);
-  if (virt_binfo)
+  else
     {
-      /* This is a reinterpret cast, we choose to do nothing.  */
-      if (force)
-        warning ("pointer to member cast via virtual base `%T'",
-                BINFO_TYPE (virt_binfo));
+      virt_binfo = binfo_from_vbase (binfo);
+      if (!virt_binfo)
+       result = BINFO_OFFSET (binfo);
       else
-       error ("pointer to member conversion via virtual base `%T'",
-              BINFO_TYPE (virt_binfo));
-      return delta;
+       {
+         /* This is a reinterpret cast, we choose to do nothing.  */
+         if (force)
+           warning ("pointer to member cast via virtual base `%T'",
+                    BINFO_TYPE (virt_binfo));
+         else
+           error ("pointer to member conversion via virtual base `%T'",
+                  BINFO_TYPE (virt_binfo));
+       }
     }
-  delta = BINFO_OFFSET (binfo);
 
-  return cp_convert (ptrdiff_type_node, delta);
+  return fold (convert_to_integer (ptrdiff_type_node, result));
 }
 
 /* Return a constructor for the pointer-to-member-function TYPE using
    the other components as specified.  */
 
 tree
-build_ptrmemfunc1 (type, delta, pfn)
-     tree type, delta, pfn;
+build_ptrmemfunc1 (tree type, tree delta, tree pfn)
 {
   tree u = NULL_TREE;
   tree delta_field;
@@ -5779,7 +5358,8 @@ build_ptrmemfunc1 (type, delta, pfn)
   u = tree_cons (pfn_field, pfn,
                 build_tree_list (delta_field, delta));
   u = build_constructor (type, u);
-  TREE_CONSTANT (u) = TREE_CONSTANT (pfn) && TREE_CONSTANT (delta);
+  TREE_CONSTANT (u) = TREE_CONSTANT (pfn) & TREE_CONSTANT (delta);
+  TREE_INVARIANT (u) = TREE_INVARIANT (pfn) & TREE_INVARIANT (delta);
   TREE_STATIC (u) = (TREE_CONSTANT (u)
                     && (initializer_constant_valid_p (pfn, TREE_TYPE (pfn))
                         != NULL_TREE)
@@ -5800,9 +5380,7 @@ build_ptrmemfunc1 (type, delta, pfn)
    Return error_mark_node, if something goes wrong.  */
 
 tree
-build_ptrmemfunc (type, pfn, force)
-     tree type, pfn;
-     int force;
+build_ptrmemfunc (tree type, tree pfn, int force)
 {
   tree fn;
   tree pfn_type;
@@ -5855,7 +5433,7 @@ build_ptrmemfunc (type, pfn, force)
        }
 
       /* Just adjust the DELTA field.  */
-      delta = cp_convert (ptrdiff_type_node, delta);
+      my_friendly_assert (TREE_TYPE (delta) == ptrdiff_type_node, 20030727);
       if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta)
        n = cp_build_binary_op (LSHIFT_EXPR, n, integer_one_node);
       delta = cp_build_binary_op (PLUS_EXPR, delta, n);
@@ -5883,14 +5461,11 @@ build_ptrmemfunc (type, pfn, force)
    given by CST.
 
    ??? There is no consistency as to the types returned for the above
-   values.  Some code acts as if its a sizetype and some as if its
+   values.  Some code acts as if it were a sizetype and some as if it were
    integer_type_node.  */
 
 void
-expand_ptrmemfunc_cst (cst, delta, pfn)
-     tree cst;
-     tree *delta;
-     tree *pfn;
+expand_ptrmemfunc_cst (tree cst, tree *delta, tree *pfn)
 {
   tree type = TREE_TYPE (cst);
   tree fn = PTRMEM_CST_MEMBER (cst);
@@ -5953,8 +5528,7 @@ expand_ptrmemfunc_cst (cst, delta, pfn)
    given by T.  */
 
 tree
-pfn_from_ptrmemfunc (t)
-     tree t;
+pfn_from_ptrmemfunc (tree t)
 {
   if (TREE_CODE (t) == PTRMEM_CST)
     {
@@ -5974,15 +5548,10 @@ pfn_from_ptrmemfunc (t)
    marked EXPR.  */
 
 tree
-dubious_conversion_warnings (type, expr, errtype, fndecl, parmnum)
-     tree type;
-     tree expr;
-     const char *errtype;
-     tree fndecl;
-     int parmnum;
+dubious_conversion_warnings (tree type, tree expr,
+                            const char *errtype, tree fndecl, int parmnum)
 {
-  if (TREE_CODE (type) == REFERENCE_TYPE)
-    type = TREE_TYPE (type);
+  type = non_reference (type);
   
   /* Issue warnings about peculiar, but valid, uses of NULL.  */
   if (ARITHMETIC_TYPE_P (type) && expr == null_node)
@@ -6006,10 +5575,9 @@ dubious_conversion_warnings (type, expr, errtype, fndecl, parmnum)
     }
   /* And warn about assigning a negative value to an unsigned
      variable.  */
-  else if (TREE_UNSIGNED (type) && TREE_CODE (type) != BOOLEAN_TYPE)
+  else if (TYPE_UNSIGNED (type) && TREE_CODE (type) != BOOLEAN_TYPE)
     {
-      if (TREE_CODE (expr) == INTEGER_CST
-         && TREE_NEGATED_INT (expr))
+      if (TREE_CODE (expr) == INTEGER_CST && TREE_NEGATED_INT (expr))
        {
          if (fndecl)
            warning ("passing negative value `%E' for %s %P of `%D'",
@@ -6034,21 +5602,11 @@ dubious_conversion_warnings (type, expr, errtype, fndecl, parmnum)
    FNDECL.  */
 
 static tree
-convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
-     tree type, rhs;
-     const char *errtype;
-     tree fndecl;
-     int parmnum;
+convert_for_assignment (tree type, tree rhs,
+                       const char *errtype, tree fndecl, int parmnum)
 {
-  register enum tree_code codel = TREE_CODE (type);
-  register tree rhstype;
-  register enum tree_code coder;
-
-  if (codel == OFFSET_TYPE)
-    abort ();
-
-  if (TREE_CODE (rhs) == OFFSET_REF)
-    rhs = resolve_offset_ref (rhs);
+  tree rhstype;
+  enum tree_code coder;
 
   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
@@ -6057,13 +5615,15 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
   rhstype = TREE_TYPE (rhs);
   coder = TREE_CODE (rhstype);
 
+  if (TREE_CODE (type) == VECTOR_TYPE && coder == VECTOR_TYPE
+      && vector_types_convertible_p (type, rhstype))
+    return convert (type, rhs);
+
   if (rhs == error_mark_node || rhstype == error_mark_node)
     return error_mark_node;
   if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
     return error_mark_node;
 
-  rhs = dubious_conversion_warnings (type, rhs, errtype, fndecl, parmnum);
-
   /* The RHS of an assignment cannot have void type.  */
   if (coder == VOID_TYPE)
     {
@@ -6138,16 +5698,12 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
    If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything.  */
 
 tree
-convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
-     tree exp, type, rhs;
-     int flags;
-     const char *errtype;
-     tree fndecl;
-     int parmnum;
+convert_for_initialization (tree exp, tree type, tree rhs, int flags,
+                           const char *errtype, tree fndecl, int parmnum)
 {
-  register enum tree_code codel = TREE_CODE (type);
-  register tree rhstype;
-  register enum tree_code coder;
+  enum tree_code codel = TREE_CODE (type);
+  tree rhstype;
+  enum tree_code coder;
 
   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
@@ -6160,13 +5716,6 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
     return error_mark_node;
 
-  if (TREE_CODE (rhs) == OFFSET_REF)
-    {
-      rhs = resolve_offset_ref (rhs);
-      if (rhs == error_mark_node)
-       return error_mark_node;
-    }
-
   if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
     rhs = convert_from_reference (rhs);
 
@@ -6178,7 +5727,7 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
          && (TREE_CODE (type) != REFERENCE_TYPE
              || TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE))
       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
-    rhs = default_conversion (rhs);
+    rhs = decay_conversion (rhs);
 
   rhstype = TREE_TYPE (rhs);
   coder = TREE_CODE (rhstype);
@@ -6196,7 +5745,8 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
 
       if (fndecl)
        savew = warningcount, savee = errorcount;
-      rhs = initialize_reference (type, rhs, /*decl=*/NULL_TREE);
+      rhs = initialize_reference (type, rhs, /*decl=*/NULL_TREE,
+                                 /*cleanup=*/NULL);
       if (fndecl)
        {
          if (warningcount > savew)
@@ -6212,8 +5762,7 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
   if (exp == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (rhstype) == REFERENCE_TYPE)
-    rhstype = TREE_TYPE (rhstype);
+  rhstype = non_reference (rhstype);
 
   type = complete_type (type);
 
@@ -6233,17 +5782,14 @@ convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
    up operands that are expected to be in memory.  */
 
 void
-c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
-     tree string, outputs, inputs, clobbers;
-     int vol;
-     const char *filename;
-     int line;
+c_expand_asm_operands (tree string, tree outputs, tree inputs, tree clobbers,
+                      int vol, location_t locus)
 {
   int noutputs = list_length (outputs);
-  register int i;
+  int i;
   /* o[I] is the place that output number I should be written.  */
-  register tree *o = (tree *) alloca (noutputs * sizeof (tree));
-  register tree tail;
+  tree *o = alloca (noutputs * sizeof (tree));
+  tree tail;
 
   /* Record the contents of OUTPUTS before it is modified.  */
   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
@@ -6252,7 +5798,7 @@ c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
   /* Generate the ASM_OPERANDS insn;
      store into the TREE_VALUEs of OUTPUTS some trees for
      where the values were actually stored.  */
-  expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
+  expand_asm_operands (string, outputs, inputs, clobbers, vol, locus);
 
   /* Copy all the intermediate outputs into the specified outputs.  */
   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
@@ -6284,11 +5830,10 @@ c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
 }
 \f
 /* If RETVAL is the address of, or a reference to, a local variable or
-   temporary give an appropraite warning.  */
+   temporary give an appropriate warning.  */
 
 static void
-maybe_warn_about_returning_address_of_local (retval)
-     tree retval;
+maybe_warn_about_returning_address_of_local (tree retval)
 {
   tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
   tree whats_returned = retval;
@@ -6314,8 +5859,6 @@ maybe_warn_about_returning_address_of_local (retval)
       if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR
          || TREE_CODE (whats_returned) == TARGET_EXPR)
        {
-         /* Get the target.  */
-         whats_returned = TREE_OPERAND (whats_returned, 0);
          warning ("returning reference to temporary");
          return;
        }
@@ -6328,7 +5871,7 @@ maybe_warn_about_returning_address_of_local (retval)
        }
     }
 
-  if (TREE_CODE (whats_returned) == VAR_DECL
+  if (DECL_P (whats_returned)
       && DECL_NAME (whats_returned)
       && DECL_FUNCTION_SCOPE_P (whats_returned)
       && !(TREE_STATIC (whats_returned)
@@ -6350,8 +5893,7 @@ maybe_warn_about_returning_address_of_local (retval)
    the DECL_RESULT for the function.  */
 
 tree
-check_return_expr (retval)
-     tree retval;
+check_return_expr (tree retval)
 {
   tree result;
   /* The type actually returned by the function, after any
@@ -6403,7 +5945,8 @@ check_return_expr (retval)
      that's supposed to return a value.  */
   if (!retval && fn_returns_value_p)
     {
-      pedwarn ("return-statement with no value, in function declared with a non-void return type");
+      pedwarn ("return-statement with no value, in function returning '%T'",
+              valtype);
       /* Clear this, so finish_function won't say that we reach the
         end of a non-void function (which we don't, we gave a
         return!).  */
@@ -6419,7 +5962,8 @@ check_return_expr (retval)
           its side-effects.  */
          finish_expr_stmt (retval);
       else
-       pedwarn ("return-statement with a value, in function declared with a void return type");
+       pedwarn ("return-statement with a value, in function "
+                 "returning 'void'");
 
       current_function_returns_null = 1;
 
@@ -6465,8 +6009,7 @@ check_return_expr (retval)
      returned expression uses the chosen variable somehow.  And people expect
      this restriction, anyway.  (jason 2000-11-19)
 
-     See finish_function, genrtl_start_function, and declare_return_variable
-     for other pieces of this optimization.  */
+     See finish_function and finalize_nrv for the rest of this optimization.  */
 
   if (fn_returns_value_p && flag_elide_constructors)
     {
@@ -6539,11 +6082,9 @@ check_return_expr (retval)
    const-qualified.  */
 
 static int
-comp_ptr_ttypes_real (to, from, constp)
-     tree to, from;
-     int constp;
+comp_ptr_ttypes_real (tree to, tree from, int constp)
 {
-  int to_more_cv_qualified = 0;
+  bool to_more_cv_qualified = false;
 
   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
     {
@@ -6551,9 +6092,9 @@ comp_ptr_ttypes_real (to, from, constp)
        return 0;
 
       if (TREE_CODE (from) == OFFSET_TYPE
-         && same_type_p (TYPE_OFFSET_BASETYPE (from),
-                         TYPE_OFFSET_BASETYPE (to)))
-         continue;
+         && !same_type_p (TYPE_OFFSET_BASETYPE (from),
+                          TYPE_OFFSET_BASETYPE (to)))
+       return 0;
 
       /* Const and volatile mean something different for function types,
         so the usual checks are not appropriate.  */
@@ -6566,15 +6107,14 @@ comp_ptr_ttypes_real (to, from, constp)
            {
              if (constp == 0)
                return 0;
-             else
-               ++to_more_cv_qualified;
+             to_more_cv_qualified = true;
            }
 
          if (constp > 0)
            constp &= TYPE_READONLY (to);
        }
 
-      if (TREE_CODE (to) != POINTER_TYPE)
+      if (TREE_CODE (to) != POINTER_TYPE && !TYPE_PTRMEM_P (to))
        return ((constp >= 0 || to_more_cv_qualified)
                && same_type_ignoring_top_level_qualifiers_p (to, from));
     }
@@ -6585,8 +6125,7 @@ comp_ptr_ttypes_real (to, from, constp)
    types to this function.  */
 
 int
-comp_ptr_ttypes (to, from)
-     tree to, from;
+comp_ptr_ttypes (tree to, tree from)
 {
   return comp_ptr_ttypes_real (to, from, 1);
 }
@@ -6595,8 +6134,7 @@ comp_ptr_ttypes (to, from)
    type or inheritance-related types, regardless of cv-quals.  */
 
 int
-ptr_reasonably_similar (to, from)
-     tree to, from;
+ptr_reasonably_similar (tree to, tree from)
 {
   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
     {
@@ -6611,7 +6149,7 @@ ptr_reasonably_similar (to, from)
       if (TREE_CODE (from) == OFFSET_TYPE
          && comptypes (TYPE_OFFSET_BASETYPE (to),
                        TYPE_OFFSET_BASETYPE (from), 
-                       COMPARE_BASE | COMPARE_RELAXED))
+                       COMPARE_BASE | COMPARE_DERIVED))
        continue;
 
       if (TREE_CODE (to) == INTEGER_TYPE
@@ -6624,15 +6162,14 @@ ptr_reasonably_similar (to, from)
       if (TREE_CODE (to) != POINTER_TYPE)
        return comptypes
          (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 
-          COMPARE_BASE | COMPARE_RELAXED);
+          COMPARE_BASE | COMPARE_DERIVED);
     }
 }
 
 /* Like comp_ptr_ttypes, for const_cast.  */
 
 static int
-comp_ptr_ttypes_const (to, from)
-     tree to, from;
+comp_ptr_ttypes_const (tree to, tree from)
 {
   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
     {
@@ -6649,47 +6186,11 @@ comp_ptr_ttypes_const (to, from)
     }
 }
 
-/* Like comp_ptr_ttypes, for reinterpret_cast.  */
-
-static int
-comp_ptr_ttypes_reinterpret (to, from)
-     tree to, from;
-{
-  int constp = 1;
-
-  for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
-    {
-      if (TREE_CODE (from) == OFFSET_TYPE)
-       from = TREE_TYPE (from);
-      if (TREE_CODE (to) == OFFSET_TYPE)
-       to = TREE_TYPE (to);
-
-      /* Const and volatile mean something different for function types,
-        so the usual checks are not appropriate.  */
-      if (TREE_CODE (from) != FUNCTION_TYPE && TREE_CODE (from) != METHOD_TYPE
-         && TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
-       {
-         if (!at_least_as_qualified_p (to, from))
-           return 0;
-
-         if (! constp
-             && !at_least_as_qualified_p (from, to))
-           return 0;
-         constp &= TYPE_READONLY (to);
-       }
-
-      if (TREE_CODE (from) != POINTER_TYPE
-         || TREE_CODE (to) != POINTER_TYPE)
-       return 1;
-    }
-}
-
 /* Returns the type qualifiers for this type, including the qualifiers on the
    elements for an array type.  */
 
 int
-cp_type_quals (type)
-     tree type;
+cp_type_quals (tree type)
 {
   type = strip_array_types (type);
   if (type == error_mark_node)
@@ -6697,11 +6198,10 @@ cp_type_quals (type)
   return TYPE_QUALS (type);
 }
 
-/* Returns nonzero if the TYPE contains a mutable member */
+/* Returns nonzero if the TYPE contains a mutable member */
 
-int
-cp_has_mutable_p (type)
-     tree type;
+bool
+cp_has_mutable_p (tree type)
 {
   type = strip_array_types (type);
 
@@ -6713,9 +6213,7 @@ cp_has_mutable_p (type)
    if and only if there is no implicit conversion from T1 to T2.  */
 
 static void
-casts_away_constness_r (t1, t2)
-     tree *t1;
-     tree *t2;
+casts_away_constness_r (tree *t1, tree *t2)
 {
   int quals1;
   int quals2;
@@ -6727,9 +6225,9 @@ casts_away_constness_r (t1, t2)
      pointer to member level is ignored when determining if a const
      cv-qualifier has been cast away.  */
   if (TYPE_PTRMEM_P (*t1))
-    *t1 = build_pointer_type (TREE_TYPE (TREE_TYPE (*t1)));
+    *t1 = build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (*t1));
   if (TYPE_PTRMEM_P (*t2))
-    *t2 = build_pointer_type (TREE_TYPE (TREE_TYPE (*t2)));
+    *t2 = build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (*t2));
 
   /* [expr.const.cast]
 
@@ -6773,10 +6271,8 @@ casts_away_constness_r (t1, t2)
 /* Returns nonzero if casting from TYPE1 to TYPE2 casts away
    constness.  */
 
-static int
-casts_away_constness (t1, t2)
-     tree t1;
-     tree t2;
+static bool
+casts_away_constness (tree t1, tree t2)
 {
   if (TREE_CODE (t2) == REFERENCE_TYPE)
     {
@@ -6786,8 +6282,7 @@ casts_away_constness (t1, t2)
         using a reference cast casts away constness if a cast from an
         rvalue of type "pointer to T1" to the type "pointer to T2"
         casts away constness.  */
-      t1 = (TREE_CODE (t1) == REFERENCE_TYPE
-           ? TREE_TYPE (t1) : t1);
+      t1 = (TREE_CODE (t1) == REFERENCE_TYPE ? TREE_TYPE (t1) : t1);
       return casts_away_constness (build_pointer_type (t1),
                                   build_pointer_type (TREE_TYPE (t2)));
     }
@@ -6801,39 +6296,32 @@ casts_away_constness (t1, t2)
        "pointer to T1" to the type "pointer to T2" casts away
        constness.  */
     return casts_away_constness
-      (build_pointer_type (TREE_TYPE (TREE_TYPE (t1))),
-       build_pointer_type (TREE_TYPE (TREE_TYPE (t2))));
+      (build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t1)),
+       build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t2)));
 
   /* Casting away constness is only something that makes sense for
      pointer or reference types.  */
   if (TREE_CODE (t1) != POINTER_TYPE 
       || TREE_CODE (t2) != POINTER_TYPE)
-    return 0;
+    return false;
 
   /* Top-level qualifiers don't matter.  */
   t1 = TYPE_MAIN_VARIANT (t1);
   t2 = TYPE_MAIN_VARIANT (t2);
   casts_away_constness_r (&t1, &t2);
   if (!can_convert (t2, t1))
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
-/* Returns TYPE with its cv qualifiers removed
-   TYPE is T cv* .. *cv where T is not a pointer type,
-   returns T * .. *. (If T is an array type, then the cv qualifiers
-   above are those of the array members.)  */
+/* If T is a REFERENCE_TYPE return the type to which T refers.
+   Otherwise, return T itself.  */
 
-static tree
-strip_all_pointer_quals (type)
-     tree type;
+tree
+non_reference (tree t)
 {
-  if (TREE_CODE (type) == POINTER_TYPE)
-    return build_pointer_type (strip_all_pointer_quals (TREE_TYPE (type)));
-  else if (TREE_CODE (type) == OFFSET_TYPE)
-    return build_offset_type (TYPE_OFFSET_BASETYPE (type),
-                             strip_all_pointer_quals (TREE_TYPE (type)));
-  else
-    return TYPE_MAIN_VARIANT (type);
+  if (TREE_CODE (t) == REFERENCE_TYPE)
+    t = TREE_TYPE (t);
+  return t;
 }