]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/cp/typeck.c
c-common.c (skip_evaluation): Don't define.
[gcc.git] / gcc / cp / typeck.c
index e34fa675b9f7e55a51411b0d77ce20642e54daa0..e3ed871f718f0a5b863615be31be0bc4d1cc736c 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, 2004, 2005, 2006, 2007, 2008
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
@@ -48,7 +48,7 @@ along with GCC; see the file COPYING3.  If not see
 static tree pfn_from_ptrmemfunc (tree);
 static tree delta_from_ptrmemfunc (tree);
 static tree convert_for_assignment (tree, tree, const char *, tree, int,
-                                   tsubst_flags_t);
+                                   tsubst_flags_t, int);
 static tree cp_pointer_int_sum (enum tree_code, tree, tree);
 static tree rationalize_conditional_expr (enum tree_code, tree, 
                                          tsubst_flags_t);
@@ -61,7 +61,7 @@ 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);
-static int convert_arguments (int, tree *, tree, tree, tree, int,
+static int convert_arguments (tree, VEC(tree,gc) **, tree, int,
                               tsubst_flags_t);
 
 /* Do `exp = require_complete_type (exp);' to make sure exp
@@ -145,7 +145,7 @@ complete_type_or_else (tree type, tree value)
     return NULL_TREE;
   else if (!COMPLETE_TYPE_P (type))
     {
-      cxx_incomplete_type_diagnostic (value, type, 0);
+      cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
       return NULL_TREE;
     }
   else
@@ -248,29 +248,38 @@ original_type (tree t)
   return cp_build_qualified_type (t, quals);
 }
 
-/* T1 and T2 are arithmetic or enumeration types.  Return the type
-   that will result from the "usual arithmetic conversions" on T1 and
-   T2 as described in [expr].  */
+/* Return the common type for two arithmetic types T1 and T2 under the
+   usual arithmetic conversions.  The default conversions have already
+   been applied, and enumerated types converted to their compatible
+   integer types.  */
 
-tree
-type_after_usual_arithmetic_conversions (tree t1, tree t2)
+static tree
+cp_common_type (tree t1, tree t2)
 {
   enum tree_code code1 = TREE_CODE (t1);
   enum tree_code code2 = TREE_CODE (t2);
   tree attributes;
 
+  /* In what follows, we slightly generalize the rules given in [expr] so
+     as to deal with `long long' and `complex'.  First, merge the
+     attributes.  */
+  attributes = (*targetm.merge_type_attributes) (t1, t2);
+
+  if (SCOPED_ENUM_P (t1) || SCOPED_ENUM_P (t2))
+    {
+      if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
+       return build_type_attribute_variant (t1, attributes);
+      else
+       return NULL_TREE;
+    }
+
   /* FIXME: Attributes.  */
   gcc_assert (ARITHMETIC_TYPE_P (t1)
              || TREE_CODE (t1) == VECTOR_TYPE
-             || TREE_CODE (t1) == ENUMERAL_TYPE);
+             || UNSCOPED_ENUM_P (t1));
   gcc_assert (ARITHMETIC_TYPE_P (t2)
              || TREE_CODE (t2) == VECTOR_TYPE
-             || TREE_CODE (t2) == ENUMERAL_TYPE);
-
-  /* In what follows, we slightly generalize the rules given in [expr] so
-     as to deal with `long long' and `complex'.  First, merge the
-     attributes.  */
-  attributes = (*targetm.merge_type_attributes) (t1, t2);
+             || UNSCOPED_ENUM_P (t2));
 
   /* If one type is complex, form the common type of the non-complex
      components, then make that complex.  Use T1 or T2 if it is the
@@ -307,13 +316,6 @@ type_after_usual_arithmetic_conversions (tree t1, tree t2)
   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
     return build_type_attribute_variant (t2, attributes);
 
-  /* Perform the integral promotions.  */
-  if (code1 != REAL_TYPE)
-    {
-      t1 = type_promotes_to (t1);
-      t2 = type_promotes_to (t2);
-    }
-
   /* Both real or both integers; use the one with greater precision.  */
   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
     return build_type_attribute_variant (t1, attributes);
@@ -393,6 +395,31 @@ type_after_usual_arithmetic_conversions (tree t1, tree t2)
     }
 }
 
+/* T1 and T2 are arithmetic or enumeration types.  Return the type
+   that will result from the "usual arithmetic conversions" on T1 and
+   T2 as described in [expr].  */
+
+tree
+type_after_usual_arithmetic_conversions (tree t1, tree t2)
+{
+  gcc_assert (ARITHMETIC_TYPE_P (t1)
+             || TREE_CODE (t1) == VECTOR_TYPE
+             || UNSCOPED_ENUM_P (t1));
+  gcc_assert (ARITHMETIC_TYPE_P (t2)
+             || TREE_CODE (t2) == VECTOR_TYPE
+             || UNSCOPED_ENUM_P (t2));
+
+  /* Perform the integral promotions.  We do not promote real types here.  */
+  if (INTEGRAL_OR_ENUMERATION_TYPE_P (t1)
+      && INTEGRAL_OR_ENUMERATION_TYPE_P (t2))
+    {
+      t1 = type_promotes_to (t1);
+      t2 = type_promotes_to (t2);
+    }
+
+  return cp_common_type (t1, t2);
+}
+
 /* Subroutine of composite_pointer_type to implement the recursive
    case.  See that function for documentation fo the parameters.  */
 
@@ -435,7 +462,7 @@ composite_pointer_type_r (tree t1, tree t2, const char* location,
   else
     {
       if (complain & tf_error)
-       permerror ("%s between distinct pointer types %qT and %qT "
+       permerror (input_location, "%s between distinct pointer types %qT and %qT "
                   "lacks a cast",
                   location, t1, t2);
       result_type = void_type_node;
@@ -450,7 +477,7 @@ composite_pointer_type_r (tree t1, tree t2, const char* location,
       if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
                        TYPE_PTRMEM_CLASS_TYPE (t2))
          && (complain & tf_error))
-       permerror ("%s between distinct pointer types %qT and %qT "
+       permerror (input_location, "%s between distinct pointer types %qT and %qT "
                   "lacks a cast",
                   location, t1, t2);
       result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
@@ -511,9 +538,10 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2,
       tree attributes;
       tree result_type;
 
-      if (pedantic && TYPE_PTRFN_P (t2) && (complain & tf_error))
-       pedwarn ("ISO C++ forbids %s between pointer of type %<void *%> "
-                "and pointer-to-function", location);
+      if (TYPE_PTRFN_P (t2) && (complain & tf_error))
+       pedwarn (input_location, OPT_pedantic, "ISO C++ forbids %s "
+                "between pointer of type %<void *%> and pointer-to-function",
+                location);
       result_type
        = cp_build_qualified_type (void_type_node,
                                   (cp_type_quals (TREE_TYPE (t1))
@@ -617,6 +645,20 @@ merge_types (tree t1, tree t2)
 
   code1 = TREE_CODE (t1);
   code2 = TREE_CODE (t2);
+  if (code1 != code2)
+    {
+      gcc_assert (code1 == TYPENAME_TYPE || code2 == TYPENAME_TYPE);
+      if (code1 == TYPENAME_TYPE)
+       {
+          t1 = resolve_typename_type (t1, /*only_current_p=*/true);
+         code1 = TREE_CODE (t1);
+       }
+      else
+       {
+          t2 = resolve_typename_type (t2, /*only_current_p=*/true);
+         code2 = TREE_CODE (t2);
+       }
+    }
 
   switch (code1)
     {
@@ -743,39 +785,42 @@ merge_types (tree t1, tree t2)
     return cp_build_type_attribute_variant (t1, attributes);
 }
 
-/* Return the common type of two types.
-   We assume that comptypes has already been done and returned 1;
-   if that isn't so, this may crash.
+/* Wrapper around cp_common_type that is used by c-common.c and other
+   front end optimizations that remove promotions.  
 
-   This is the type for the result of most arithmetic operations
-   if the operands have the given two types.  */
+   Return the common type for two arithmetic types T1 and T2 under the
+   usual arithmetic conversions.  The default conversions have already
+   been applied, and enumerated types converted to their compatible
+   integer types.  */
 
 tree
 common_type (tree t1, tree t2)
 {
-  enum tree_code code1;
-  enum tree_code code2;
+  /* If one type is nonsense, use the other  */
+  if (t1 == error_mark_node)
+    return t2;
+  if (t2 == error_mark_node)
+    return t1;
 
-  /* If one type is nonsense, bail.  */
-  if (t1 == error_mark_node || t2 == error_mark_node)
-    return error_mark_node;
+  return cp_common_type (t1, t2);
+}
 
-  code1 = TREE_CODE (t1);
-  code2 = TREE_CODE (t2);
+/* Return the common type of two pointer types T1 and T2.  This is the
+   type for the result of most arithmetic operations if the operands
+   have the given two types.
+   We assume that comp_target_types has already been done and returned
+   nonzero; if that isn't so, this may crash.  */
 
-  if ((ARITHMETIC_TYPE_P (t1) || code1 == ENUMERAL_TYPE
-       || code1 == VECTOR_TYPE)
-      && (ARITHMETIC_TYPE_P (t2) || code2 == ENUMERAL_TYPE
-         || code2 == VECTOR_TYPE))
-    return type_after_usual_arithmetic_conversions (t1, t2);
-
-  else if ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
-          || (TYPE_PTRMEM_P (t1) && TYPE_PTRMEM_P (t2))
-          || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)))
-    return composite_pointer_type (t1, t2, error_mark_node, error_mark_node,
-                                  "conversion", tf_warning_or_error);
-  else
-    gcc_unreachable ();
+tree
+common_pointer_type (tree t1, tree t2)
+{
+  gcc_assert ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
+              || (TYPE_PTRMEM_P (t1) && TYPE_PTRMEM_P (t2))
+              || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)));
+
+  return composite_pointer_type (t1, t2, error_mark_node, error_mark_node,
+                                 "conversion", tf_warning_or_error);
 }
 \f
 /* Compare two exception specifier types for exactness or subsetness, if
@@ -1278,8 +1323,9 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
   type = non_reference (type);
   if (TREE_CODE (type) == METHOD_TYPE)
     {
-      if (complain && (pedantic || warn_pointer_arith))
-       pedwarn ("invalid application of %qs to a member function", 
+      if (complain)
+       pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
+                "invalid application of %qs to a member function", 
                 operator_name_info[(int) op].name);
       value = size_one_node;
     }
@@ -1303,7 +1349,7 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
       return value;
     }
 
-  return c_sizeof_or_alignof_type (complete_type (type),
+  return c_sizeof_or_alignof_type (input_location, complete_type (type),
                                   op == SIZEOF_EXPR,
                                   complain);
 }
@@ -1355,7 +1401,7 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain)
   else if (is_overloaded_fn (e))
     {
       if (complain & tf_error)
-        permerror ("ISO C++ forbids applying %<sizeof%> to an expression of "
+        permerror (input_location, "ISO C++ forbids applying %<sizeof%> to an expression of "
                    "function type");
       else
         return error_mark_node;
@@ -1415,7 +1461,7 @@ cxx_alignof_expr (tree e, tsubst_flags_t complain)
   else if (is_overloaded_fn (e))
     {
       if (complain & tf_error)
-        permerror ("ISO C++ forbids applying %<__alignof%> to an expression of "
+        permerror (input_location, "ISO C++ forbids applying %<__alignof%> to an expression of "
                    "function type");
       else
         return error_mark_node;
@@ -1470,7 +1516,7 @@ cxx_sizeof_or_alignof_expr (tree e, enum tree_code op, bool complain)
 bool
 invalid_nonstatic_memfn_p (const_tree expr, tsubst_flags_t complain)
 {
-  if (TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE)
+  if (expr && DECL_NONSTATIC_MEMBER_FUNCTION_P (expr))
     {
       if (complain & tf_error)
         error ("invalid use of non-static member function");
@@ -1645,7 +1691,7 @@ decay_conversion (tree exp)
   return exp;
 }
 
-/* Perform prepatory conversions, as part of the "usual arithmetic
+/* Perform preparatory conversions, as part of the "usual arithmetic
    conversions".  In particular, as per [expr]:
 
      Whenever an lvalue expression appears as an operand of an
@@ -1661,10 +1707,14 @@ decay_conversion (tree exp)
 tree
 default_conversion (tree exp)
 {
+  /* Check for target-specific promotions.  */
+  tree promoted_type = targetm.promoted_type (TREE_TYPE (exp));
+  if (promoted_type)
+    exp = cp_convert (promoted_type, exp);
   /* Perform the integral promotions first so that bitfield
      expressions (which may promote to "int", even if the bitfield is
      declared "unsigned") are promoted correctly.  */
-  if (INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
+  else if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
     exp = perform_integral_promotions (exp);
   /* Perform the other conversions.  */
   exp = decay_conversion (exp);
@@ -1696,18 +1746,6 @@ perform_integral_promotions (tree expr)
   return expr;
 }
 
-/* Take the address of an inline function without setting TREE_ADDRESSABLE
-   or TREE_USED.  */
-
-tree
-inline_conversion (tree exp)
-{
-  if (TREE_CODE (exp) == FUNCTION_DECL)
-    exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
-
-  return exp;
-}
-
 /* Returns nonzero iff exp is a STRING_CST or the result of applying
    decay_conversion to one.  */
 
@@ -1883,7 +1921,7 @@ build_class_member_access_expr (tree object, tree member,
       member_scope = DECL_CLASS_CONTEXT (member);
       mark_used (member);
       if (TREE_DEPRECATED (member))
-       warn_deprecated_use (member);
+       warn_deprecated_use (member, NULL_TREE);
     }
   else
     member_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (member));
@@ -1981,7 +2019,7 @@ build_class_member_access_expr (tree object, tree member,
       if (null_object_p && warn_invalid_offsetof
          && CLASSTYPE_NON_POD_P (object_type)
          && !DECL_FIELD_IS_BASE (member)
-         && !skip_evaluation
+         && cp_unevaluated_operand == 0
          && (complain & tf_warning))
        {
          warning (OPT_Winvalid_offsetof, 
@@ -2089,8 +2127,8 @@ build_class_member_access_expr (tree object, tree member,
   return result;
 }
 
-/* Return the destructor denoted by OBJECT.SCOPE::~DTOR_NAME, or, if
-   SCOPE is NULL, by OBJECT.~DTOR_NAME.  */
+/* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
+   SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type.  */
 
 static tree
 lookup_destructor (tree object, tree scope, tree dtor_name)
@@ -2105,7 +2143,21 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
             scope, dtor_type);
       return error_mark_node;
     }
-  if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
+  if (TREE_CODE (dtor_type) == IDENTIFIER_NODE)
+    {
+      /* In a template, names we can't find a match for are still accepted
+        destructor names, and we check them here.  */
+      if (check_dtor_name (object_type, dtor_type))
+       dtor_type = object_type;
+      else
+       {
+         error ("object type %qT does not match destructor name ~%qT",
+                object_type, dtor_type);
+         return error_mark_node;
+       }
+      
+    }
+  else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
     {
       error ("the type being destroyed is %qT, but the destructor refers to %qT",
             TYPE_MAIN_VARIANT (object_type), dtor_type);
@@ -2146,7 +2198,7 @@ check_template_keyword (tree decl)
       && TREE_CODE (decl) != TEMPLATE_ID_EXPR)
     {
       if (!is_overloaded_fn (decl))
-       permerror ("%qD is not a template", decl);
+       permerror (input_location, "%qD is not a template", decl);
       else
        {
          tree fns;
@@ -2166,7 +2218,7 @@ check_template_keyword (tree decl)
              fns = OVL_NEXT (fns);
            }
          if (!fns)
-           permerror ("%qD is not a template", decl);
+           permerror (input_location, "%qD is not a template", decl);
        }
     }
 }
@@ -2315,10 +2367,10 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
 
       if (is_template_id)
        {
-         tree template = member;
+         tree templ = member;
 
-         if (BASELINK_P (template))
-           template = lookup_template_function (template, template_args);
+         if (BASELINK_P (templ))
+           templ = lookup_template_function (templ, template_args);
          else
            {
              if (complain & tf_error)
@@ -2329,7 +2381,7 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
     }
 
   if (TREE_DEPRECATED (member))
-    warn_deprecated_use (member);
+    warn_deprecated_use (member, NULL_TREE);
 
   if (template_p)
     check_template_keyword (member);
@@ -2397,6 +2449,10 @@ build_x_indirect_ref (tree expr, const char *errorstring,
 
   if (processing_template_decl)
     {
+      /* Retain the type if we know the operand is a pointer so that
+        describable_type doesn't make auto deduction break.  */
+      if (TREE_TYPE (expr) && POINTER_TYPE_P (TREE_TYPE (expr)))
+       return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
       if (type_dependent_expression_p (expr))
        return build_min_nt (INDIRECT_REF, expr);
       expr = build_non_dependent_expr (expr);
@@ -2415,7 +2471,8 @@ build_x_indirect_ref (tree expr, const char *errorstring,
 
 /* Helper function called from c-common.  */
 tree
-build_indirect_ref (tree ptr, const char *errorstring)
+build_indirect_ref (location_t loc __attribute__ ((__unused__)),
+                   tree ptr, const char *errorstring)
 {
   return cp_build_indirect_ref (ptr, errorstring, tf_warning_or_error);
 }
@@ -2441,12 +2498,8 @@ cp_build_indirect_ref (tree ptr, const char *errorstring,
       /* [expr.unary.op]
 
         If the type of the expression is "pointer to T," the type
-        of  the  result  is  "T."
-
-        We must use the canonical variant because certain parts of
-        the back end, like fold, do pointer comparisons between
-        types.  */
-      tree t = canonical_type_variant (TREE_TYPE (type));
+        of  the  result  is  "T."  */
+      tree t = TREE_TYPE (type);
 
       if (CONVERT_EXPR_P (ptr)
           || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
@@ -2515,14 +2568,18 @@ cp_build_indirect_ref (tree ptr, const char *errorstring,
 
    If INDEX is of some user-defined type, it must be converted to
    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
-   will inherit the type of the array, which will be some pointer type.  */
+   will inherit the type of the array, which will be some pointer type.
+   
+   LOC is the location to use in building the array reference.  */
 
 tree
-build_array_ref (tree array, tree idx)
+build_array_ref (location_t loc, tree array, tree idx)
 {
+  tree ret;
+
   if (idx == 0)
     {
-      error ("subscript missing in array reference");
+      error_at (loc, "subscript missing in array reference");
       return error_mark_node;
     }
 
@@ -2536,17 +2593,21 @@ build_array_ref (tree array, tree idx)
     {
     case COMPOUND_EXPR:
       {
-       tree value = build_array_ref (TREE_OPERAND (array, 1), idx);
-       return build2 (COMPOUND_EXPR, TREE_TYPE (value),
-                      TREE_OPERAND (array, 0), value);
+       tree value = build_array_ref (loc, TREE_OPERAND (array, 1), idx);
+       ret = build2 (COMPOUND_EXPR, TREE_TYPE (value),
+                     TREE_OPERAND (array, 0), value);
+       SET_EXPR_LOCATION (ret, loc);
+       return ret;
       }
 
     case COND_EXPR:
-      return build_conditional_expr
-       (TREE_OPERAND (array, 0),
-        build_array_ref (TREE_OPERAND (array, 1), idx),
-        build_array_ref (TREE_OPERAND (array, 2), idx),
-         tf_warning_or_error);
+      ret = build_conditional_expr
+             (TREE_OPERAND (array, 0),
+              build_array_ref (loc, TREE_OPERAND (array, 1), idx),
+              build_array_ref (loc, TREE_OPERAND (array, 2), idx),
+              tf_warning_or_error);
+      protected_set_expr_location (ret, loc);
+      return ret;
 
     default:
       break;
@@ -2558,9 +2619,9 @@ build_array_ref (tree array, tree idx)
 
       warn_array_subscript_with_type_char (idx);
 
-      if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
+      if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
        {
-         error ("array subscript is not an integer");
+         error_at (loc, "array subscript is not an integer");
          return error_mark_node;
        }
 
@@ -2596,8 +2657,9 @@ build_array_ref (tree array, tree idx)
            return error_mark_node;
        }
 
-      if (pedantic && !lvalue_p (array))
-       pedwarn ("ISO C++ forbids subscripting non-lvalue array");
+      if (!lvalue_p (array))
+       pedwarn (loc, OPT_pedantic, 
+                "ISO C++ forbids subscripting non-lvalue array");
 
       /* Note in C++ it is valid to subscript a `register' array, since
         it is valid to take the address of something with that
@@ -2608,7 +2670,8 @@ build_array_ref (tree array, tree idx)
          while (TREE_CODE (foo) == COMPONENT_REF)
            foo = TREE_OPERAND (foo, 0);
          if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
-           warning (OPT_Wextra, "subscripting array declared %<register%>");
+           warning_at (loc, OPT_Wextra,
+                       "subscripting array declared %<register%>");
        }
 
       type = TREE_TYPE (TREE_TYPE (array));
@@ -2621,7 +2684,9 @@ build_array_ref (tree array, tree idx)
        |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
       TREE_THIS_VOLATILE (rval)
        |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
-      return require_complete_type (fold_if_not_in_template (rval));
+      ret = require_complete_type (fold_if_not_in_template (rval));
+      protected_set_expr_location (ret, loc);
+      return ret;
     }
 
   {
@@ -2641,21 +2706,24 @@ build_array_ref (tree array, tree idx)
 
     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
       {
-       error ("subscripted value is neither array nor pointer");
+       error_at (loc, "subscripted value is neither array nor pointer");
        return error_mark_node;
       }
     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
       {
-       error ("array subscript is not an integer");
+       error_at (loc, "array subscript is not an integer");
        return error_mark_node;
       }
 
     warn_array_subscript_with_type_char (idx);
 
-    return cp_build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind,
-                                                  tf_warning_or_error),
-                                  "array indexing",
-                                  tf_warning_or_error);
+    ret = cp_build_indirect_ref (cp_build_binary_op (input_location,
+                                                    PLUS_EXPR, ar, ind,
+                                                    tf_warning_or_error),
+                                 "array indexing",
+                                 tf_warning_or_error);
+    protected_set_expr_location (ret, loc);
+    return ret;
   }
 }
 \f
@@ -2713,16 +2781,20 @@ get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function)
       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
        {
        case ptrmemfunc_vbit_in_pfn:
-         e1 = cp_build_binary_op (BIT_AND_EXPR, idx, integer_one_node,
+         e1 = cp_build_binary_op (input_location,
+                                  BIT_AND_EXPR, idx, integer_one_node,
                                   tf_warning_or_error);
-         idx = cp_build_binary_op (MINUS_EXPR, idx, integer_one_node,
+         idx = cp_build_binary_op (input_location,
+                                   MINUS_EXPR, idx, integer_one_node,
                                    tf_warning_or_error);
          break;
 
        case ptrmemfunc_vbit_in_delta:
-         e1 = cp_build_binary_op (BIT_AND_EXPR, delta, integer_one_node,
+         e1 = cp_build_binary_op (input_location,
+                                  BIT_AND_EXPR, delta, integer_one_node,
                                   tf_warning_or_error);
-         delta = cp_build_binary_op (RSHIFT_EXPR, delta, integer_one_node,
+         delta = cp_build_binary_op (input_location,
+                                     RSHIFT_EXPR, delta, integer_one_node,
                                      tf_warning_or_error);
          break;
 
@@ -2758,6 +2830,10 @@ get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function)
       vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
                     instance_ptr);
       vtbl = cp_build_indirect_ref (vtbl, NULL, tf_warning_or_error);
+      /* If the object is not dynamic the access invokes undefined
+        behavior.  As it is not executed in this case silence the
+        spurious warnings it may provoke.  */
+      TREE_NO_WARNING (vtbl) = 1;
 
       /* Finally, extract the function pointer from the vtable.  */
       e2 = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (vtbl), vtbl,
@@ -2788,25 +2864,69 @@ get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function)
 
 /* Used by the C-common bits.  */
 tree
-build_function_call (tree function, tree params)
+build_function_call (location_t loc ATTRIBUTE_UNUSED, 
+                    tree function, tree params)
 {
   return cp_build_function_call (function, params, tf_warning_or_error);
 }
 
+/* Used by the C-common bits.  */
+tree
+build_function_call_vec (location_t loc ATTRIBUTE_UNUSED,
+                        tree function, VEC(tree,gc) *params,
+                        VEC(tree,gc) *origtypes ATTRIBUTE_UNUSED)
+{
+  VEC(tree,gc) *orig_params = params;
+  tree ret = cp_build_function_call_vec (function, &params,
+                                        tf_warning_or_error);
+
+  /* cp_build_function_call_vec can reallocate PARAMS by adding
+     default arguments.  That should never happen here.  Verify
+     that.  */
+  gcc_assert (params == orig_params);
+
+  return ret;
+}
+
+/* Build a function call using a tree list of arguments.  */
+
 tree
 cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
+{
+  VEC(tree,gc) *vec;
+  tree ret;
+
+  vec = make_tree_vector ();
+  for (; params != NULL_TREE; params = TREE_CHAIN (params))
+    VEC_safe_push (tree, gc, vec, TREE_VALUE (params));
+  ret = cp_build_function_call_vec (function, &vec, complain);
+  release_tree_vector (vec);
+  return ret;
+}
+
+/* Build a function call using a vector of arguments.  PARAMS may be
+   NULL if there are no parameters.  This changes the contents of
+   PARAMS.  */
+
+tree
+cp_build_function_call_vec (tree function, VEC(tree,gc) **params,
+                           tsubst_flags_t complain)
 {
   tree fntype, fndecl;
   tree name = NULL_TREE;
   int is_method;
   tree original = function;
-  int nargs, parm_types_len;
+  int nargs;
   tree *argarray;
   tree parm_types;
+  VEC(tree,gc) *allocated = NULL;
+  tree ret;
 
   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
      expressions, like those used for ObjC messenger dispatches.  */
-  function = objc_rewrite_function_call (function, params);
+  if (params != NULL && !VEC_empty (tree, *params))
+    function = objc_rewrite_function_call (function,
+                                          VEC_index (tree, *params, 0));
 
   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
@@ -2822,17 +2942,11 @@ cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
       fndecl = function;
 
       /* Convert anything with function type to a pointer-to-function.  */
-      if (pedantic && DECL_MAIN_P (function) && (complain & tf_error))
-       pedwarn ("ISO C++ forbids calling %<::main%> from within program");
-
-      /* Differs from default_conversion by not setting TREE_ADDRESSABLE
-        (because calling an inline function does not mean the function
-        needs to be separately compiled).  */
+      if (DECL_MAIN_P (function) && (complain & tf_error))
+       pedwarn (input_location, OPT_pedantic, 
+                "ISO C++ forbids calling %<::main%> from within program");
 
-      if (DECL_INLINE (function))
-       function = inline_conversion (function);
-      else
-       function = build_addr_func (function);
+      function = build_addr_func (function);
     }
   else
     {
@@ -2872,64 +2986,55 @@ cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
   fntype = TREE_TYPE (fntype);
   parm_types = TYPE_ARG_TYPES (fntype);
 
-  /* Allocate storage for converted arguments.  */
-  parm_types_len = list_length (parm_types);
-  nargs = list_length (params);
-  if (parm_types_len > nargs)
-    nargs = parm_types_len;
-  argarray = (tree *) alloca (nargs * sizeof (tree));
-
-  /* Convert the parameters to the types declared in the
-     function prototype, or apply default promotions.  */
-  nargs = convert_arguments (nargs, argarray, parm_types,
-                            params, fndecl, LOOKUP_NORMAL,
-                             complain);
+  if (params == NULL)
+    {
+      allocated = make_tree_vector ();
+      params = &allocated;
+    }
+
+  nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
+                            complain);
   if (nargs < 0)
     return error_mark_node;
 
-  /* Check that arguments to builtin functions match the expectations.  */
-  if (fndecl
-      && DECL_BUILT_IN (fndecl)
-      && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
-      && !check_builtin_function_arguments (fndecl, nargs, argarray))
-    return error_mark_node;
+  argarray = VEC_address (tree, *params);
 
   /* Check for errors in format strings and inappropriately
      null parameters.  */
   check_function_arguments (TYPE_ATTRIBUTES (fntype), nargs, argarray,
                            parm_types);
 
-  return build_cxx_call (function, nargs, argarray);
+  ret = build_cxx_call (function, nargs, argarray);
+
+  if (allocated != NULL)
+    release_tree_vector (allocated);
+
+  return ret;
 }
 \f
-/* Convert the actual parameter expressions in the list VALUES
-   to the types in the list TYPELIST.
+/* Convert the actual parameter expressions in the list VALUES to the
+   types in the list TYPELIST.  The converted expressions are stored
+   back in the VALUES vector.
    If parmdecls is exhausted, or when an element has NULL as its type,
    perform the default conversions.
 
-   Store the converted arguments in ARGARRAY.  NARGS is the size of this array.
-
    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
 
    This is also where warnings about wrong number of args are generated.
 
    Returns the actual number of arguments processed (which might be less
-   than NARGS), or -1 on error.
-
-   VALUES is a chain of TREE_LIST nodes with the elements of the list
-   in the TREE_VALUE slots of those nodes.
+   than the length of the vector), or -1 on error.
 
    In C++, unspecified trailing parameters can be filled in with their
    default arguments, if such were specified.  Do so here.  */
 
 static int
-convert_arguments (int nargs, tree *argarray,
-                  tree typelist, tree values, tree fndecl, int flags,
-                   tsubst_flags_t complain)
+convert_arguments (tree typelist, VEC(tree,gc) **values, tree fndecl,
+                  int flags, tsubst_flags_t complain)
 {
-  tree typetail, valtail;
+  tree typetail;
   const char *called_thing = 0;
-  int i = 0;
+  unsigned int i;
 
   /* Argument passing is always copy-initialization.  */
   flags |= LOOKUP_ONLYCONVERTING;
@@ -2948,12 +3053,12 @@ convert_arguments (int nargs, tree *argarray,
        called_thing = "function";
     }
 
-  for (valtail = values, typetail = typelist;
-       valtail;
-       valtail = TREE_CHAIN (valtail), i++)
+  for (i = 0, typetail = typelist;
+       i < VEC_length (tree, *values);
+       i++)
     {
       tree type = typetail ? TREE_VALUE (typetail) : 0;
-      tree val = TREE_VALUE (valtail);
+      tree val = VEC_index (tree, *values, i);
 
       if (val == error_mark_node || type == error_mark_node)
        return -1;
@@ -3022,7 +3127,7 @@ convert_arguments (int nargs, tree *argarray,
          if (parmval == error_mark_node)
            return -1;
 
-         argarray[i] = parmval;
+         VEC_replace (tree, *values, i, parmval);
        }
       else
        {
@@ -3035,7 +3140,7 @@ convert_arguments (int nargs, tree *argarray,
          else
            val = convert_arg_to_ellipsis (val);
 
-         argarray[i] = val;
+         VEC_replace (tree, *values, i, val);
        }
 
       if (typetail)
@@ -3064,7 +3169,7 @@ convert_arguments (int nargs, tree *argarray,
              if (parmval == error_mark_node)
                return -1;
 
-             argarray[i] = parmval;
+             VEC_safe_push (tree, gc, *values, parmval);
              typetail = TREE_CHAIN (typetail);
              /* ends with `...'.  */
              if (typetail == NULL_TREE)
@@ -3088,8 +3193,7 @@ convert_arguments (int nargs, tree *argarray,
        }
     }
 
-  gcc_assert (i <= nargs);
-  return i;
+  return (int) i;
 }
 \f
 /* Build a binary-operation expression, after performing default
@@ -3139,7 +3243,7 @@ build_x_binary_op (enum tree_code code, tree arg1, enum tree_code arg1_code,
       && !error_operand_p (arg2)
       && (code != LSHIFT_EXPR
          || !CLASS_TYPE_P (TREE_TYPE (arg1))))
-    warn_about_parentheses (code, arg1_code, arg2_code);
+    warn_about_parentheses (code, arg1_code, orig_arg1, arg2_code, orig_arg2);
 
   if (processing_template_decl && expr != error_mark_node)
     return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
@@ -3147,17 +3251,46 @@ build_x_binary_op (enum tree_code code, tree arg1, enum tree_code arg1_code,
   return expr;
 }
 
+/* Build and return an ARRAY_REF expression.  */
+
+tree
+build_x_array_ref (tree arg1, tree arg2, tsubst_flags_t complain)
+{
+  tree orig_arg1 = arg1;
+  tree orig_arg2 = arg2;
+  tree expr;
+
+  if (processing_template_decl)
+    {
+      if (type_dependent_expression_p (arg1)
+         || type_dependent_expression_p (arg2))
+       return build_min_nt (ARRAY_REF, arg1, arg2,
+                            NULL_TREE, NULL_TREE);
+      arg1 = build_non_dependent_expr (arg1);
+      arg2 = build_non_dependent_expr (arg2);
+    }
+
+  expr = build_new_op (ARRAY_REF, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
+                      /*overloaded_p=*/NULL, complain);
+
+  if (processing_template_decl && expr != error_mark_node)
+    return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
+                             NULL_TREE, NULL_TREE);
+  return expr;
+}
+
 /* For the c-common bits.  */
 tree
-build_binary_op (enum tree_code code, tree op0, tree op1,
+build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
                 int convert_p ATTRIBUTE_UNUSED)
 {
-  return cp_build_binary_op(code, op0, op1, tf_warning_or_error);
+  return cp_build_binary_op (location, code, op0, op1, tf_warning_or_error);
 }
 
 
 /* Build a binary-operation expression without default conversions.
    CODE is the kind of expression to build.
+   LOCATION is the location_t of the operator in the source code.
    This function differs from `build' in several ways:
    the data type of the result is computed and recorded in it,
    warnings are generated if arg data types are invalid,
@@ -3175,7 +3308,8 @@ build_binary_op (enum tree_code code, tree op0, tree op1,
    multiple inheritance, and deal with pointer to member functions.  */
 
 tree
-cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
+cp_build_binary_op (location_t location,
+                   enum tree_code code, tree orig_op0, tree orig_op1,
                    tsubst_flags_t complain)
 {
   tree op0, op1;
@@ -3258,7 +3392,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
       if (t != error_mark_node)
        {
          if (complain & tf_error)
-           permerror ("assuming cast to type %qT from overloaded function",
+           permerror (input_location, "assuming cast to type %qT from overloaded function",
                       TREE_TYPE (t));
          op0 = t;
        }
@@ -3269,7 +3403,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
       if (t != error_mark_node)
        {
          if (complain & tf_error)
-           permerror ("assuming cast to type %qT from overloaded function",
+           permerror (input_location, "assuming cast to type %qT from overloaded function",
                       TREE_TYPE (t));
          op1 = t;
        }
@@ -3304,9 +3438,9 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
          && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
                                                        TREE_TYPE (type1)))
-       return pointer_diff (op0, op1, common_type (type0, type1));
+       return pointer_diff (op0, op1, common_pointer_type (type0, type1));
       /* In all other cases except pointer - int, the usual arithmetic
-        rules aply.  */
+        rules apply.  */
       else if (!(code0 == POINTER_TYPE && code1 == INTEGER_TYPE))
        {
          common = 1;
@@ -3350,7 +3484,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        {
          enum tree_code tcode0 = code0, tcode1 = code1;
 
-         warn_for_div_by_zero (op1);
+         warn_for_div_by_zero (location, op1);
 
          if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
            tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
@@ -3386,9 +3520,13 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
 
     case TRUNC_MOD_EXPR:
     case FLOOR_MOD_EXPR:
-      warn_for_div_by_zero (op1);
+      warn_for_div_by_zero (location, op1);
 
-      if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
+      if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
+         && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
+         && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
+       common = 1;
+      else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
        {
          /* Although it would be tempting to shorten always here, that loses
             on some targets, since the modulo instruction is undefined if the
@@ -3421,13 +3559,15 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
            {
              if (tree_int_cst_lt (op1, integer_zero_node))
                {
-                 if (complain & tf_warning)
+                 if ((complain & tf_warning)
+                     && c_inhibit_evaluation_warnings == 0)
                    warning (0, "right shift count is negative");
                }
              else
                {
                  if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0
-                     && (complain & tf_warning))
+                     && (complain & tf_warning)
+                     && c_inhibit_evaluation_warnings == 0)
                    warning (0, "right shift count >= width of type");
                }
            }
@@ -3448,12 +3588,14 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
            {
              if (tree_int_cst_lt (op1, integer_zero_node))
                {
-                 if (complain & tf_warning)
+                 if ((complain & tf_warning)
+                     && c_inhibit_evaluation_warnings == 0)
                    warning (0, "left shift count is negative");
                }
              else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
                {
-                 if (complain & tf_warning)
+                 if ((complain & tf_warning)
+                     && c_inhibit_evaluation_warnings == 0)
                    warning (0, "left shift count >= width of type");
                }
            }
@@ -3508,9 +3650,9 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
 
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
-          || code0 == COMPLEX_TYPE)
+          || code0 == COMPLEX_TYPE || code0 == ENUMERAL_TYPE)
          && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
-             || code1 == COMPLEX_TYPE))
+             || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
        short_compare = 1;
       else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
               || (TYPE_PTRMEM_P (type0) && TYPE_PTRMEM_P (type1)))
@@ -3544,7 +3686,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        {
          result_type = type0;
          if (complain & tf_error) 
-            permerror ("ISO C++ forbids comparison between pointer and integer");
+            permerror (input_location, "ISO C++ forbids comparison between pointer and integer");
           else
             return error_mark_node;
        }
@@ -3552,7 +3694,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        {
          result_type = type1;
          if (complain & tf_error)
-           permerror ("ISO C++ forbids comparison between pointer and integer");
+           permerror (input_location, "ISO C++ forbids comparison between pointer and integer");
           else
             return error_mark_node;
        }
@@ -3563,18 +3705,22 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
            {
              tree pfn0 = pfn_from_ptrmemfunc (op0);
              tree delta0 = delta_from_ptrmemfunc (op0);
-             tree e1 = cp_build_binary_op (EQ_EXPR,
+             tree e1 = cp_build_binary_op (location,
+                                           EQ_EXPR,
                                            pfn0,       
                                            fold_convert (TREE_TYPE (pfn0),
                                                          integer_zero_node),
                                            complain);
-             tree e2 = cp_build_binary_op (BIT_AND_EXPR, 
+             tree e2 = cp_build_binary_op (location,
+                                           BIT_AND_EXPR, 
                                            delta0,
                                            integer_one_node,
                                            complain);
-             e2 = cp_build_binary_op (EQ_EXPR, e2, integer_zero_node,
+             e2 = cp_build_binary_op (location,
+                                      EQ_EXPR, e2, integer_zero_node,
                                       complain);
-             op0 = cp_build_binary_op (TRUTH_ANDIF_EXPR, e1, e2,
+             op0 = cp_build_binary_op (location,
+                                       TRUTH_ANDIF_EXPR, e1, e2,
                                        complain);
              op1 = cp_convert (TREE_TYPE (op0), integer_one_node); 
            }
@@ -3586,7 +3732,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
          result_type = TREE_TYPE (op0);
        }
       else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (op0))
-       return cp_build_binary_op (code, op1, op0, complain);
+       return cp_build_binary_op (location, code, op1, op0, complain);
       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
        {
          tree type;
@@ -3634,28 +3780,34 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
                 pointer-to-member is any member with a zero PFN and
                 LSB of the DELTA field is 0.  */
 
-             e1 = cp_build_binary_op (BIT_AND_EXPR,
+             e1 = cp_build_binary_op (location, BIT_AND_EXPR,
                                       delta0, 
                                       integer_one_node,
                                       complain);
-             e1 = cp_build_binary_op (EQ_EXPR, e1, integer_zero_node,
+             e1 = cp_build_binary_op (location,
+                                      EQ_EXPR, e1, integer_zero_node,
                                       complain);
-             e2 = cp_build_binary_op (BIT_AND_EXPR,
+             e2 = cp_build_binary_op (location, BIT_AND_EXPR,
                                       delta1,
                                       integer_one_node,
                                       complain);
-             e2 = cp_build_binary_op (EQ_EXPR, e2, integer_zero_node,
+             e2 = cp_build_binary_op (location,
+                                      EQ_EXPR, e2, integer_zero_node,
                                       complain);
-             e1 = cp_build_binary_op (TRUTH_ANDIF_EXPR, e2, e1,
+             e1 = cp_build_binary_op (location,
+                                      TRUTH_ANDIF_EXPR, e2, e1,
                                       complain);
-             e2 = cp_build_binary_op (EQ_EXPR,
+             e2 = cp_build_binary_op (location, EQ_EXPR,
                                       pfn0,
                                       fold_convert (TREE_TYPE (pfn0),
                                                     integer_zero_node),
                                       complain);
-             e2 = cp_build_binary_op (TRUTH_ANDIF_EXPR, e2, e1, complain);
-             e1 = cp_build_binary_op (EQ_EXPR, delta0, delta1, complain);
-             e1 = cp_build_binary_op (TRUTH_ORIF_EXPR, e1, e2, complain);
+             e2 = cp_build_binary_op (location,
+                                      TRUTH_ANDIF_EXPR, e2, e1, complain);
+             e1 = cp_build_binary_op (location,
+                                      EQ_EXPR, delta0, delta1, complain);
+             e1 = cp_build_binary_op (location,
+                                      TRUTH_ORIF_EXPR, e1, e2, complain);
            }
          else
            {
@@ -3668,19 +3820,24 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
                 pointer-to-member is any member with a zero PFN; the
                 DELTA field is unspecified.  */
  
-             e1 = cp_build_binary_op (EQ_EXPR, delta0, delta1, complain);
-             e2 = cp_build_binary_op (EQ_EXPR,
+             e1 = cp_build_binary_op (location,
+                                      EQ_EXPR, delta0, delta1, complain);
+             e2 = cp_build_binary_op (location,
+                                      EQ_EXPR,
                                       pfn0,
                                       fold_convert (TREE_TYPE (pfn0),
                                                     integer_zero_node),
                                       complain);
-             e1 = cp_build_binary_op (TRUTH_ORIF_EXPR, e1, e2, complain);
+             e1 = cp_build_binary_op (location,
+                                      TRUTH_ORIF_EXPR, e1, e2, complain);
            }
          e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1);
-         e = cp_build_binary_op (TRUTH_ANDIF_EXPR, e2, e1, complain);
+         e = cp_build_binary_op (location,
+                                 TRUTH_ANDIF_EXPR, e2, e1, complain);
          if (code == EQ_EXPR)
            return e;
-         return cp_build_binary_op (EQ_EXPR, e, integer_zero_node, complain);
+         return cp_build_binary_op (location,
+                                    EQ_EXPR, e, integer_zero_node, complain);
        }
       else
        {
@@ -3732,7 +3889,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        {
          result_type = type0;
          if (complain & tf_error)
-           permerror ("ISO C++ forbids comparison between pointer and integer");
+           permerror (input_location, "ISO C++ forbids comparison between pointer and integer");
           else
             return error_mark_node;
        }
@@ -3740,7 +3897,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        {
          result_type = type1;
          if (complain & tf_error)
-           permerror ("ISO C++ forbids comparison between pointer and integer");
+           permerror (input_location, "ISO C++ forbids comparison between pointer and integer");
           else
             return error_mark_node;
        }
@@ -3767,9 +3924,10 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
       break;
     }
 
-  if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
+  if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
+       || code0 == ENUMERAL_TYPE)
        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
-          || code1 == COMPLEX_TYPE)))
+          || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)))
     arithmetic_types_p = 1;
   else
     {
@@ -3781,7 +3939,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
              || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
                                                        TREE_TYPE (type1)))
            {
-             binary_op_error (code, type0, type1);
+             binary_op_error (location, code, type0, type1);
              return error_mark_node;
            }
          arithmetic_types_p = 1;
@@ -3791,7 +3949,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
   if (!result_type
       && arithmetic_types_p
       && (shorten || common || short_compare))
-    result_type = common_type (type0, type1);
+    result_type = cp_common_type (type0, type1);
 
   if (!result_type)
     {
@@ -3828,66 +3986,14 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
         For them, this optimization is safe only if
         both args are zero-extended or both are sign-extended.
         Otherwise, we might change the result.
-        Eg, (short)-1 | (unsigned short)-1 is (int)-1
+        E.g., (short)-1 | (unsigned short)-1 is (int)-1
         but calculated in (unsigned short) it would be (unsigned short)-1.  */
 
       if (shorten && none_complex)
        {
-         int unsigned0, unsigned1;
-         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 = TYPE_UNSIGNED (result_type);
-         tree type;
-
          final_type = result_type;
-
-         /* Handle the case that OP0 does not *contain* a conversion
-            but it *requires* conversion to FINAL_TYPE.  */
-
-         if (op0 == arg0 && TREE_TYPE (op0) != final_type)
-           unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
-         if (op1 == arg1 && TREE_TYPE (op1) != final_type)
-           unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
-
-         /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
-
-         /* For bitwise operations, signedness of nominal type
-            does not matter.  Consider only how operands were extended.  */
-         if (shorten == -1)
-           uns = unsigned0;
-
-         /* Note that in all three cases below we refrain from optimizing
-            an unsigned operation on sign-extended args.
-            That would not be valid.  */
-
-         /* Both args variable: if both extended in same way
-            from same width, do it in that width.
-            Do it unsigned if args were zero-extended.  */
-         if ((TYPE_PRECISION (TREE_TYPE (arg0))
-              < TYPE_PRECISION (result_type))
-             && (TYPE_PRECISION (TREE_TYPE (arg1))
-                 == TYPE_PRECISION (TREE_TYPE (arg0)))
-             && unsigned0 == unsigned1
-             && (unsigned0 || !uns))
-           result_type = c_common_signed_or_unsigned_type
-             (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
-         else if (TREE_CODE (arg0) == INTEGER_CST
-                  && (unsigned1 || !uns)
-                  && (TYPE_PRECISION (TREE_TYPE (arg1))
-                      < TYPE_PRECISION (result_type))
-                  && (type = c_common_signed_or_unsigned_type
-                      (unsigned1, TREE_TYPE (arg1)),
-                      int_fits_type_p (arg0, type)))
-           result_type = type;
-         else if (TREE_CODE (arg1) == INTEGER_CST
-                  && (unsigned0 || !uns)
-                  && (TYPE_PRECISION (TREE_TYPE (arg0))
-                      < TYPE_PRECISION (result_type))
-                  && (type = c_common_signed_or_unsigned_type
-                      (unsigned0, TREE_TYPE (arg0)),
-                      int_fits_type_p (arg1, type)))
-           result_type = type;
+         result_type = shorten_binary_op (result_type, op0, op1, 
+                                          shorten == -1);
        }
 
       /* Comparison operations are shortened too but differently.
@@ -3914,115 +4020,11 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
          && 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)
+         && !processing_template_decl
+          && (complain & tf_warning))
        {
-         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);
-         tree primop1 = get_narrower (op1, &unsignedp1);
-
-         /* Check for comparison of different enum types.  */
-         if (TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE
-             && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE
-             && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0))
-                != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1))
-             && (complain & tf_warning))
-           {
-             warning (OPT_Wsign_compare, "comparison between types %q#T and %q#T",
-                      TREE_TYPE (orig_op0), TREE_TYPE (orig_op1));
-           }
-
-         /* Give warnings for comparisons between signed and unsigned
-            quantities that may fail.  */
-         /* Do the checking based on the original operand trees, so that
-            casts will be considered, but default promotions won't be.  */
-
-         /* 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 (!TYPE_UNSIGNED (result_type))
-           /* OK */;
-         /* Do not warn if both operands are unsigned.  */
-         else if (op0_signed == op1_signed)
-           /* OK */;
-         /* Do not warn if the signed quantity is an unsuffixed
-            integer literal (or some static constant expression
-            involving such literals or a conditional expression
-            involving such literals) and it is non-negative.  */
-         else if ((op0_signed && tree_expr_nonnegative_p (orig_op0))
-                  || (op1_signed && tree_expr_nonnegative_p (orig_op1)))
-           /* OK */;
-         /* Do not warn if the comparison is an equality operation,
-            the unsigned quantity is an integral constant and it does
-            not use the most significant bit of result_type.  */
-         else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR)
-                  && ((op0_signed && TREE_CODE (orig_op1) == INTEGER_CST
-                       && int_fits_type_p (orig_op1, c_common_signed_type
-                                           (result_type)))
-                       || (op1_signed && TREE_CODE (orig_op0) == INTEGER_CST
-                           && int_fits_type_p (orig_op0, c_common_signed_type
-                                               (result_type)))))
-           /* OK */;
-         else if (complain & tf_warning)
-           warning (OPT_Wsign_compare, 
-                    "comparison between signed and unsigned integer expressions");
-
-         /* Warn if two unsigned values are being compared in a size
-            larger than their original size, and one (and only one) is the
-            result of a `~' operator.  This comparison will always fail.
-
-            Also warn if one operand is a constant, and the constant does not
-            have all bits set that are set in the ~ operand when it is
-            extended.  */
-
-         if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
-             ^ (TREE_CODE (primop1) == BIT_NOT_EXPR))
-           {
-             if (TREE_CODE (primop0) == BIT_NOT_EXPR)
-               primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
-             if (TREE_CODE (primop1) == BIT_NOT_EXPR)
-               primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
-
-             if (host_integerp (primop0, 0) || host_integerp (primop1, 0))
-               {
-                 tree primop;
-                 HOST_WIDE_INT constant, mask;
-                 int unsignedp;
-                 unsigned int bits;
-
-                 if (host_integerp (primop0, 0))
-                   {
-                     primop = primop1;
-                     unsignedp = unsignedp1;
-                     constant = tree_low_cst (primop0, 0);
-                   }
-                 else
-                   {
-                     primop = primop0;
-                     unsignedp = unsignedp0;
-                     constant = tree_low_cst (primop1, 0);
-                   }
-
-                 bits = TYPE_PRECISION (TREE_TYPE (primop));
-                 if (bits < TYPE_PRECISION (result_type)
-                     && bits < HOST_BITS_PER_LONG && unsignedp)
-                   {
-                     mask = (~ (HOST_WIDE_INT) 0) << bits;
-                     if ((mask & constant) != mask
-                         && (complain & tf_warning))
-                       warning (OPT_Wsign_compare, "comparison of promoted ~unsigned with constant");
-                   }
-               }
-             else if (unsignedp0 && unsignedp1
-                      && (TYPE_PRECISION (TREE_TYPE (primop0))
-                          < TYPE_PRECISION (result_type))
-                      && (TYPE_PRECISION (TREE_TYPE (primop1))
-                          < TYPE_PRECISION (result_type))
-                      && (complain & tf_warning))
-               warning (OPT_Wsign_compare, "comparison of promoted ~unsigned with unsigned");
-           }
+         warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1, 
+                                result_type, resultcode);
        }
     }
 
@@ -4071,7 +4073,7 @@ cp_build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
   if (TREE_OVERFLOW_P (result) 
       && !TREE_OVERFLOW_P (op0) 
       && !TREE_OVERFLOW_P (op1))
-    overflow_warning (result);
+    overflow_warning (location, result);
 
   return result;
 }
@@ -4108,20 +4110,18 @@ pointer_diff (tree op0, tree op1, tree ptrtype)
   if (!complete_type_or_else (target_type, NULL_TREE))
     return error_mark_node;
 
-  if (pedantic || warn_pointer_arith)
-    {
-      if (TREE_CODE (target_type) == VOID_TYPE)
-       permerror ("ISO C++ forbids using pointer of type %<void *%> in subtraction");
-      if (TREE_CODE (target_type) == FUNCTION_TYPE)
-       permerror ("ISO C++ forbids using pointer to a function in subtraction");
-      if (TREE_CODE (target_type) == METHOD_TYPE)
-       permerror ("ISO C++ forbids using pointer to a method in subtraction");
-    }
+  if (TREE_CODE (target_type) == VOID_TYPE)
+    permerror (input_location, "ISO C++ forbids using pointer of type %<void *%> in subtraction");
+  if (TREE_CODE (target_type) == FUNCTION_TYPE)
+    permerror (input_location, "ISO C++ forbids using pointer to a function in subtraction");
+  if (TREE_CODE (target_type) == METHOD_TYPE)
+    permerror (input_location, "ISO C++ forbids using pointer to a method in subtraction");
 
   /* First do the subtraction as integers;
      then drop through to build the divide operator.  */
 
-  op0 = cp_build_binary_op (MINUS_EXPR,
+  op0 = cp_build_binary_op (input_location,
+                           MINUS_EXPR,
                            cp_convert (restype, op0),
                            cp_convert (restype, op1),
                            tf_warning_or_error);
@@ -4180,8 +4180,20 @@ build_x_unary_op (enum tree_code code, tree xarg, tsubst_flags_t complain)
                        /*overloaded_p=*/NULL, complain);
   if (!exp && code == ADDR_EXPR)
     {
-      /*  A pointer to member-function can be formed only by saying
-         &X::mf.  */
+      if (is_overloaded_fn (xarg))
+       {
+         tree fn = get_first_fn (xarg);
+         if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn))
+           {
+             const char *type =
+               (DECL_CONSTRUCTOR_P (fn) ? "constructor" : "destructor");
+             error ("taking address of %s %qE", type, xarg);
+             return error_mark_node;
+           }
+       }
+
+      /* A pointer to member-function can be formed only by saying
+        &X::mf.  */
       if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
          && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
        {
@@ -4191,7 +4203,7 @@ build_x_unary_op (enum tree_code code, tree xarg, tsubst_flags_t complain)
               error ("invalid use of %qE to form a pointer-to-member-function",
                      xarg);
               if (TREE_CODE (xarg) != OFFSET_REF)
-                inform ("  a qualified-id is required");
+                inform (input_location, "  a qualified-id is required");
              return error_mark_node;
            }
          else
@@ -4240,9 +4252,10 @@ cp_truthvalue_conversion (tree expr)
 {
   tree type = TREE_TYPE (expr);
   if (TYPE_PTRMEM_P (type))
-    return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
+    return build_binary_op (EXPR_LOCATION (expr),
+                           NE_EXPR, expr, integer_zero_node, 1);
   else
-    return c_common_truthvalue_conversion (expr);
+    return c_common_truthvalue_conversion (input_location, expr);
 }
 
 /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  */
@@ -4306,7 +4319,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
   tree val;
   const char *invalid_op_diag;
 
-  if (arg == error_mark_node)
+  if (error_operand_p (arg))
     return error_mark_node;
 
   if ((invalid_op_diag
@@ -4469,19 +4482,15 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
 
       {
        tree inc;
-       tree declared_type;
-       tree result_type = TREE_TYPE (arg);
+       tree declared_type = unlowered_expr_type (arg);
 
-       declared_type = unlowered_expr_type (arg);
-
-       arg = get_unwidened (arg, 0);
        argtype = TREE_TYPE (arg);
 
        /* ARM $5.2.5 last annotation says this should be forbidden.  */
        if (TREE_CODE (argtype) == ENUMERAL_TYPE)
           {
             if (complain & tf_error)
-              permerror ((code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
+              permerror (input_location, (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
                          ? G_("ISO C++ forbids incrementing an enum")
                          : G_("ISO C++ forbids decrementing an enum"));
             else
@@ -4509,7 +4518,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
                     && !TYPE_PTROB_P (argtype)) 
               {
                 if (complain & tf_error)
-                  permerror ((code == PREINCREMENT_EXPR
+                  permerror (input_location, (code == PREINCREMENT_EXPR
                               || code == POSTINCREMENT_EXPR)
                              ? G_("ISO C++ forbids incrementing a pointer of type %qT")
                              : G_("ISO C++ forbids decrementing a pointer of type %qT"),
@@ -4548,7 +4557,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
          val = build2 (code, TREE_TYPE (arg), arg, inc);
 
        TREE_SIDE_EFFECTS (val) = 1;
-       return cp_convert (result_type, val);
+       return val;
       }
 
     case ADDR_EXPR:
@@ -4569,9 +4578,12 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
       else if (pedantic && DECL_MAIN_P (arg))
         {
           /* ARM $3.4 */
-          if (complain & tf_error)
-            permerror ("ISO C++ forbids taking address of function %<::main%>");
-          else
+         /* Apparently a lot of autoconf scripts for C++ packages do this,
+            so only complain if -pedantic.  */
+          if (complain & (flag_pedantic_errors ? tf_error : tf_warning))
+            pedwarn (input_location, OPT_pedantic,
+                    "ISO C++ forbids taking address of function %<::main%>");
+          else if (flag_pedantic_errors)
             return error_mark_node;
         }
 
@@ -4631,12 +4643,12 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
              else if (current_class_type
                        && TREE_OPERAND (arg, 0) == current_class_ref)
                   /* An expression like &memfn.  */
-                permerror ("ISO C++ forbids taking the address of an unqualified"
+                permerror (input_location, "ISO C++ forbids taking the address of an unqualified"
                            " or parenthesized non-static member function to form"
                            " a pointer to member function.  Say %<&%T::%D%>",
                            base, name);
              else
-               permerror ("ISO C++ forbids taking the address of a bound member"
+               permerror (input_location, "ISO C++ forbids taking the address of a bound member"
                           " function to form a pointer to member function."
                           "  Say %<&%T::%D%>",
                           base, name);
@@ -4662,10 +4674,10 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
           /* Even if we're not being pedantic, we cannot allow this
              extension when we're instantiating in a SFINAE
              context.  */
-         if (! lvalue_p (arg) && (pedantic || complain == tf_none))
+         if (! lvalue_p (arg) && complain == tf_none)
             {
               if (complain & tf_error)
-                permerror ("ISO C++ forbids taking the address of a cast to a non-lvalue expression");
+                permerror (input_location, "ISO C++ forbids taking the address of a cast to a non-lvalue expression");
               else
                 return error_mark_node;
             }
@@ -4720,15 +4732,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
 
       /* In a template, we are processing a non-dependent expression
         so we can just form an ADDR_EXPR with the correct type.  */
-      if (processing_template_decl)
-       {
-         val = build_address (arg);
-         if (TREE_CODE (arg) == OFFSET_REF)
-           PTRMEM_OK_P (val) = PTRMEM_OK_P (arg);
-         return val;
-       }
-
-      if (TREE_CODE (arg) != COMPONENT_REF)
+      if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
        {
          val = build_address (arg);
          if (TREE_CODE (arg) == OFFSET_REF)
@@ -4793,7 +4797,8 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
 
 /* Hook for the c-common bits that build a unary op.  */
 tree
-build_unary_op (enum tree_code code, tree xarg, int noconvert)
+build_unary_op (location_t location ATTRIBUTE_UNUSED,
+               enum tree_code code, tree xarg, int noconvert)
 {
   return cp_build_unary_op (code, xarg, noconvert, tf_warning_or_error);
 }
@@ -5010,7 +5015,7 @@ tree build_x_compound_expr_from_list (tree list, const char *msg)
   if (TREE_CHAIN (list))
     {
       if (msg)
-       permerror ("%s expression list treated as compound expression", msg);
+       permerror (input_location, "%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), 
@@ -5020,6 +5025,34 @@ tree build_x_compound_expr_from_list (tree list, const char *msg)
   return expr;
 }
 
+/* Like build_x_compound_expr_from_list, but using a VEC.  */
+
+tree
+build_x_compound_expr_from_vec (VEC(tree,gc) *vec, const char *msg)
+{
+  if (VEC_empty (tree, vec))
+    return NULL_TREE;
+  else if (VEC_length (tree, vec) == 1)
+    return VEC_index (tree, vec, 0);
+  else
+    {
+      tree expr;
+      unsigned int ix;
+      tree t;
+
+      if (msg != NULL)
+       permerror (input_location,
+                  "%s expression list treated as compound expression",
+                  msg);
+
+      expr = VEC_index (tree, vec, 0);
+      for (ix = 1; VEC_iterate (tree, vec, ix, t); ++ix)
+       expr = build_x_compound_expr (expr, t, tf_warning_or_error);
+
+      return expr;
+    }
+}
+
 /* Handle overloading of the ',' operator when needed.  */
 
 tree
@@ -5052,7 +5085,7 @@ build_x_compound_expr (tree op1, tree op2, tsubst_flags_t complain)
 /* Like cp_build_compound_expr, but for the c-common bits.  */
 
 tree
-build_compound_expr (tree lhs, tree rhs)
+build_compound_expr (location_t loc ATTRIBUTE_UNUSED, tree lhs, tree rhs)
 {
   return cp_build_compound_expr (lhs, rhs, tf_warning_or_error);
 }
@@ -5080,11 +5113,22 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
       return rhs;
     }
 
+  if (type_unknown_p (rhs))
+    {
+      error ("no context to resolve type of %qE", rhs);
+      return error_mark_node;
+    }
+  
   return build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
 }
 
 /* Issue a diagnostic message if casting from SRC_TYPE to DEST_TYPE
-   casts away constness.  CAST gives the type of cast.  */
+   casts away constness.  CAST gives the type of cast.  
+
+   ??? This function warns for casting away any qualifier not just
+   const.  We would like to specify exactly what qualifiers are casted
+   away.
+*/
 
 static void
 check_for_casting_away_constness (tree src_type, tree dest_type,
@@ -5095,27 +5139,29 @@ check_for_casting_away_constness (tree src_type, tree dest_type,
   if (cast == CAST_EXPR && !warn_cast_qual)
       return;
   
-  if (casts_away_constness (src_type, dest_type))
-    switch (cast)
-      {
-      case CAST_EXPR:
-       warning (OPT_Wcast_qual, 
-                 "cast from type %qT to type %qT casts away constness",
-                src_type, dest_type);
-       return;
-       
-      case STATIC_CAST_EXPR:
-       error ("static_cast from type %qT to type %qT casts away constness",
-              src_type, dest_type);
-       return;
-       
-      case REINTERPRET_CAST_EXPR:
-       error ("reinterpret_cast from type %qT to type %qT casts away constness",
+  if (!casts_away_constness (src_type, dest_type))
+    return;
+
+  switch (cast)
+    {
+    case CAST_EXPR:
+      warning (OPT_Wcast_qual, 
+              "cast from type %qT to type %qT casts away qualifiers",
               src_type, dest_type);
-       return;
-      default:
-       gcc_unreachable();
-      }
+      return;
+      
+    case STATIC_CAST_EXPR:
+      error ("static_cast from type %qT to type %qT casts away qualifiers",
+            src_type, dest_type);
+      return;
+      
+    case REINTERPRET_CAST_EXPR:
+      error ("reinterpret_cast from type %qT to type %qT casts away qualifiers",
+            src_type, dest_type);
+      return;
+    default:
+      gcc_unreachable();
+    }
 }
 
 /* Convert EXPR (an expression with pointer-to-member type) to TYPE
@@ -5143,12 +5189,14 @@ convert_ptrmem (tree type, tree expr, bool allow_inverse_p,
        {
          tree cond, op1, op2;
 
-         cond = cp_build_binary_op (EQ_EXPR,
+         cond = cp_build_binary_op (input_location,
+                                    EQ_EXPR,
                                     expr,
                                     build_int_cst (TREE_TYPE (expr), -1),
                                     tf_warning_or_error);
          op1 = build_nop (ptrdiff_type_node, expr);
-         op2 = cp_build_binary_op (PLUS_EXPR, op1, delta,
+         op2 = cp_build_binary_op (input_location,
+                                   PLUS_EXPR, op1, delta,
                                    tf_warning_or_error);
 
          expr = fold_build3 (COND_EXPR, ptrdiff_type_node, cond, op1, op2);
@@ -5315,8 +5363,10 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
   /* The effect of all that is that any conversion between any two
      types which are integral, floating, or enumeration types can be
      performed.  */
-  if ((INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type))
-      && (INTEGRAL_TYPE_P (intype) || SCALAR_FLOAT_TYPE_P (intype)))
+  if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
+       || SCALAR_FLOAT_TYPE_P (type))
+      && (INTEGRAL_OR_ENUMERATION_TYPE_P (intype)
+         || SCALAR_FLOAT_TYPE_P (intype)))
     {
       expr = ocp_convert (type, expr, CONV_C_CAST, LOOKUP_NORMAL);
 
@@ -5450,7 +5500,8 @@ convert_member_func_to_ptr (tree type, tree expr)
              || TREE_CODE (intype) == METHOD_TYPE);
 
   if (pedantic || warn_pmf2ptr)
-    pedwarn ("converting from %qT to %qT", intype, type);
+    pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpmf_conversions,
+            "converting from %qT to %qT", intype, type);
 
   if (TREE_CODE (intype) == METHOD_TYPE)
     expr = build_addr_func (expr);
@@ -5561,7 +5612,7 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
       if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))
         {
           if (complain & tf_error)
-            permerror ("cast from %qT to %qT loses precision",
+            permerror (input_location, "cast from %qT to %qT loses precision",
                        intype, type);
           else
             return error_mark_node;
@@ -5615,7 +5666,8 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
     }
   else if (TREE_CODE (type) == VECTOR_TYPE)
     return fold_if_not_in_template (convert_to_vector (type, expr));
-  else if (TREE_CODE (intype) == VECTOR_TYPE && INTEGRAL_TYPE_P (type))
+  else if (TREE_CODE (intype) == VECTOR_TYPE
+          && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
     return fold_if_not_in_template (convert_to_integer (type, expr));
   else
     {
@@ -5790,7 +5842,7 @@ build_const_cast (tree type, tree expr, tsubst_flags_t complain)
 /* Like cp_build_c_cast, but for the c-common bits.  */
 
 tree
-build_c_cast (tree type, tree expr)
+build_c_cast (location_t loc ATTRIBUTE_UNUSED, tree type, tree expr)
 {
   return cp_build_c_cast (type, expr, tf_warning_or_error);
 }
@@ -5838,7 +5890,7 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain)
       if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
        {
           if (complain & tf_error)
-            permerror ("ISO C++ forbids casting to an array type %qT", type);
+            permerror (input_location, "ISO C++ forbids casting to an array type %qT", type);
           else
             return error_mark_node;
          type = build_pointer_type (TREE_TYPE (type));
@@ -5905,7 +5957,11 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain)
 \f
 /* For use from the C common bits.  */
 tree
-build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
+build_modify_expr (location_t location ATTRIBUTE_UNUSED,
+                  tree lhs, tree lhs_origtype ATTRIBUTE_UNUSED,
+                  enum tree_code modifycode, 
+                  location_t rhs_location ATTRIBUTE_UNUSED, tree rhs,
+                  tree rhs_origtype ATTRIBUTE_UNUSED)
 {
   return cp_build_modify_expr (lhs, modifycode, rhs, tf_warning_or_error);
 }
@@ -5925,7 +5981,6 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
   tree newrhs = rhs;
   tree lhstype = TREE_TYPE (lhs);
   tree olhstype = lhstype;
-  tree olhs = NULL_TREE;
   bool plain_assign = (modifycode == NOP_EXPR);
 
   /* Avoid duplicate error messages from operands that had errors.  */
@@ -6033,8 +6088,11 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
 
   if (modifycode == INIT_EXPR)
     {
-      if (TREE_CODE (rhs) == CONSTRUCTOR)
+      if (BRACE_ENCLOSED_INITIALIZER_P (rhs))
+       /* Do the default thing.  */;
+      else if (TREE_CODE (rhs) == CONSTRUCTOR)
        {
+         /* Compound literal.  */
          if (! same_type_p (TREE_TYPE (rhs), lhstype))
            /* Call convert to generate an error; see PR 11063.  */
            rhs = convert (lhstype, rhs);
@@ -6046,10 +6104,11 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
        /* Do the default thing.  */;
       else
        {
+         VEC(tree,gc) *rhs_vec = make_tree_vector_single (rhs);
          result = build_special_member_call (lhs, complete_ctor_identifier,
-                                             build_tree_list (NULL_TREE, rhs),
-                                             lhstype, LOOKUP_NORMAL,
+                                             &rhs_vec, lhstype, LOOKUP_NORMAL,
                                               complain);
+         release_tree_vector (rhs_vec);
          if (result == NULL_TREE)
            return error_mark_node;
          return result;
@@ -6088,7 +6147,8 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
                        || MAYBE_CLASS_TYPE_P (lhstype)));
 
          lhs = stabilize_reference (lhs);
-         newrhs = cp_build_binary_op (modifycode, lhs, rhs,
+         newrhs = cp_build_binary_op (input_location,
+                                      modifycode, lhs, rhs,
                                       complain);
          if (newrhs == error_mark_node)
            {
@@ -6128,35 +6188,11 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
        return error_mark_node;
     }
 
-  /* If storing into a structure or union member, it has probably been
-     given type `int'.  Compute the type that would go with the actual
-     amount of storage the member occupies.  */
-
-  if (TREE_CODE (lhs) == COMPONENT_REF
-      && (TREE_CODE (lhstype) == INTEGER_TYPE
-         || TREE_CODE (lhstype) == REAL_TYPE
-         || TREE_CODE (lhstype) == ENUMERAL_TYPE))
-    {
-      lhstype = TREE_TYPE (get_unwidened (lhs, 0));
+  /* If storing into a structure or union member, it may have been given a
+     lowered bitfield type.  We need to convert to the declared type first,
+     so retrieve it now.  */
 
-      /* If storing in a field that is in actuality a short or narrower
-        than one, we must store in the field in its actual type.  */
-
-      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;
-       }
-    }
+  olhstype = unlowered_expr_type (lhs);
 
   /* Convert new value to destination type.  */
 
@@ -6174,7 +6210,7 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
        }
 
       /* Allow array assignment in compiler-generated code.  */
-      if (! DECL_ARTIFICIAL (current_function_decl))
+      if (!current_function_decl || !DECL_ARTIFICIAL (current_function_decl))
        {
           /* This routine is used for both initialization and assignment.
              Make sure the diagnostic message differentiates the context.  */
@@ -6191,27 +6227,25 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
       from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
                   ? 1 + (modifycode != INIT_EXPR): 0;
       return build_vec_init (lhs, NULL_TREE, newrhs,
-                            /*explicit_default_init_p=*/false,
+                            /*explicit_value_init_p=*/false,
                             from_array, complain);
     }
 
   if (modifycode == INIT_EXPR)
-    newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
+    /* Calls with INIT_EXPR are all direct-initialization, so don't set
+       LOOKUP_ONLYCONVERTING.  */
+    newrhs = convert_for_initialization (lhs, olhstype, newrhs, LOOKUP_NORMAL,
                                         "initialization", NULL_TREE, 0,
                                          complain);
   else
+    newrhs = convert_for_assignment (olhstype, newrhs, "assignment",
+                                    NULL_TREE, 0, complain, LOOKUP_IMPLICIT);
+
+  if (!same_type_p (lhstype, olhstype))
+    newrhs = cp_convert_and_check (lhstype, newrhs);
+
+  if (modifycode != INIT_EXPR)
     {
-      /* Avoid warnings on enum bit fields.  */
-      if (TREE_CODE (olhstype) == ENUMERAL_TYPE
-         && TREE_CODE (lhstype) == INTEGER_TYPE)
-       {
-         newrhs = convert_for_assignment (olhstype, newrhs, "assignment",
-                                          NULL_TREE, 0, complain);
-         newrhs = convert_force (lhstype, newrhs, 0);
-       }
-      else
-       newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
-                                        NULL_TREE, 0, complain);
       if (TREE_CODE (newrhs) == CALL_EXPR
          && TYPE_NEEDS_CONSTRUCTING (lhstype))
        newrhs = build_cplus_new (lhstype, newrhs);
@@ -6243,21 +6277,7 @@ cp_build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
   if (!plain_assign)
     TREE_NO_WARNING (result) = 1;
 
-  /* If we got the LHS in a different type for storing in,
-     convert the result back to the nominal type of LHS
-     so that the value we return always has the same type
-     as the LHS argument.  */
-
-  if (olhstype == TREE_TYPE (result))
-    return result;
-  if (olhs)
-    {
-      result = build2 (COMPOUND_EXPR, olhstype, result, olhs);
-      TREE_NO_WARNING (result) = 1;
-      return result;
-    }
-  return convert_for_assignment (olhstype, result, "assignment",
-                                NULL_TREE, 0, complain);
+  return result;
 }
 
 tree
@@ -6477,16 +6497,18 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p)
       gcc_assert  (same_type_ignoring_top_level_qualifiers_p
                   (TREE_TYPE (delta), ptrdiff_type_node));
       if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta)
-       n = cp_build_binary_op (LSHIFT_EXPR, n, integer_one_node,
+       n = cp_build_binary_op (input_location,
+                               LSHIFT_EXPR, n, integer_one_node,
                                tf_warning_or_error);
-      delta = cp_build_binary_op (PLUS_EXPR, delta, n, tf_warning_or_error);
+      delta = cp_build_binary_op (input_location,
+                                 PLUS_EXPR, delta, n, tf_warning_or_error);
       return build_ptrmemfunc1 (to_type, delta, npfn);
     }
 
   /* Handle null pointer to member function conversions.  */
   if (integer_zerop (pfn))
     {
-      pfn = build_c_cast (type, integer_zero_node);
+      pfn = build_c_cast (input_location, type, integer_zero_node);
       return build_ptrmemfunc1 (to_type,
                                integer_zero_node,
                                pfn);
@@ -6623,7 +6645,7 @@ delta_from_ptrmemfunc (tree t)
 static tree
 convert_for_assignment (tree type, tree rhs,
                        const char *errtype, tree fndecl, int parmnum,
-                       tsubst_flags_t complain)
+                       tsubst_flags_t complain, int flags)
 {
   tree rhstype;
   enum tree_code coder;
@@ -6690,7 +6712,7 @@ convert_for_assignment (tree type, tree rhs,
      We allow bad conversions here because by the time we get to this point
      we are committed to doing the conversion.  If we end up doing a bad
      conversion, convert_like will complain.  */
-  if (!can_convert_arg_bad (type, rhstype, rhs))
+  if (!can_convert_arg_bad (type, rhstype, rhs, flags))
     {
       /* When -Wno-pmf-conversions is use, we just silently allow
         conversions from pointers-to-members to plain pointers.  If
@@ -6744,7 +6766,8 @@ convert_for_assignment (tree type, tree rhs,
       TREE_NO_WARNING (rhs) = 1;
     }
 
-  return perform_implicit_conversion (strip_top_quals (type), rhs, complain);
+  return perform_implicit_conversion_flags (strip_top_quals (type), rhs,
+                                           complain, flags);
 }
 
 /* Convert RHS to be of type TYPE.
@@ -6835,7 +6858,7 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags,
     return ocp_convert (type, rhs, CONV_IMPLICIT|CONV_FORCE_TEMP, flags);
 
   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum,
-                                complain);
+                                complain, flags);
 }
 \f
 /* If RETVAL is the address of, or a reference to, a local variable or
@@ -6964,7 +6987,7 @@ check_return_expr (tree retval, bool *no_warning)
      that's supposed to return a value.  */
   if (!retval && fn_returns_value_p)
     {
-      permerror ("return-statement with no value, in function returning %qT",
+      permerror (input_location, "return-statement with no value, in function returning %qT",
                 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
@@ -6985,9 +7008,8 @@ check_return_expr (tree retval, bool *no_warning)
           its side-effects.  */
          finish_expr_stmt (retval);
       else
-       permerror ("return-statement with a value, in function "
+       permerror (input_location, "return-statement with a value, in function "
                   "returning 'void'");
-
       current_function_returns_null = 1;
 
       /* There's really no value to return, after all.  */
@@ -7164,6 +7186,7 @@ static int
 comp_ptr_ttypes_real (tree to, tree from, int constp)
 {
   bool to_more_cv_qualified = false;
+  bool is_opaque_pointer = false;
 
   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
     {
@@ -7198,9 +7221,13 @@ comp_ptr_ttypes_real (tree to, tree from, int constp)
            constp &= TYPE_READONLY (to);
        }
 
+      if (TREE_CODE (to) == VECTOR_TYPE)
+       is_opaque_pointer = vector_targets_convertible_p (to, from);
+
       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));
+               && (is_opaque_pointer
+                   || same_type_ignoring_top_level_qualifiers_p (to, from)));
     }
 }
 
@@ -7261,6 +7288,8 @@ ptr_reasonably_similar (const_tree to, const_tree from)
 bool
 comp_ptr_ttypes_const (tree to, tree from)
 {
+  bool is_opaque_pointer = false;
+
   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
     {
       if (TREE_CODE (to) != TREE_CODE (from))
@@ -7271,8 +7300,12 @@ comp_ptr_ttypes_const (tree to, tree from)
                          TYPE_OFFSET_BASETYPE (to)))
          continue;
 
+      if (TREE_CODE (to) == VECTOR_TYPE)
+       is_opaque_pointer = vector_targets_convertible_p (to, from);
+
       if (TREE_CODE (to) != POINTER_TYPE)
-       return same_type_ignoring_top_level_qualifiers_p (to, from);
+       return (is_opaque_pointer
+               || same_type_ignoring_top_level_qualifiers_p (to, from));
     }
 }
 
@@ -7282,7 +7315,7 @@ comp_ptr_ttypes_const (tree to, tree from)
 int
 cp_type_quals (const_tree type)
 {
-  /* This CONST_CAST is okay because strip_array_types returns it's
+  /* This CONST_CAST is okay because strip_array_types returns its
      argument unmodified and we assign it to a const_tree.  */
   type = strip_array_types (CONST_CAST_TREE(type));
   if (type == error_mark_node)
@@ -7296,7 +7329,7 @@ cp_type_quals (const_tree type)
 bool
 cp_type_readonly (const_tree type)
 {
-  /* This CONST_CAST is okay because strip_array_types returns it's
+  /* This CONST_CAST is okay because strip_array_types returns its
      argument unmodified and we assign it to a const_tree.  */
   type = strip_array_types (CONST_CAST_TREE(type));
   return TYPE_READONLY (type);
@@ -7307,7 +7340,7 @@ cp_type_readonly (const_tree type)
 bool
 cp_has_mutable_p (const_tree type)
 {
-  /* This CONST_CAST is okay because strip_array_types returns it's
+  /* This CONST_CAST is okay because strip_array_types returns its
      argument unmodified and we assign it to a const_tree.  */
   type = strip_array_types (CONST_CAST_TREE(type));
 
@@ -7334,6 +7367,9 @@ cp_apply_type_quals_to_decl (int type_quals, tree decl)
   if (type == error_mark_node)
     return;
 
+  if (TREE_CODE (decl) == TYPE_DECL)
+    return;
+
   if (TREE_CODE (type) == FUNCTION_TYPE
       && type_quals != TYPE_UNQUALIFIED)
     {
@@ -7343,7 +7379,8 @@ cp_apply_type_quals_to_decl (int type_quals, tree decl)
       if (pedantic)
        {
          tree bad_type = build_qualified_type (type, type_quals);
-         pedwarn ("ignoring %qV qualifiers added to function type %qT",
+         pedwarn (input_location, OPT_pedantic, 
+                  "ignoring %qV qualifiers added to function type %qT",
                   bad_type, type);
        }
 
@@ -7429,7 +7466,12 @@ casts_away_constness_r (tree *t1, tree *t2)
 }
 
 /* Returns nonzero if casting from TYPE1 to TYPE2 casts away
-   constness.  */
+   constness.  
+
+   ??? This function returns non-zero if casting away qualifiers not
+   just const.  We would like to return to the caller exactly which
+   qualifiers are casted away to give more accurate diagnostics.
+*/
 
 static bool
 casts_away_constness (tree t1, tree t2)
@@ -7492,7 +7534,7 @@ non_reference (tree t)
    how the lvalue is being used and so selects the error message.  */
 
 int
-lvalue_or_else (const_tree ref, enum lvalue_use use, tsubst_flags_t complain)
+lvalue_or_else (tree ref, enum lvalue_use use, tsubst_flags_t complain)
 {
   int win = lvalue_p (ref);
 
This page took 0.092424 seconds and 5 git commands to generate.