OSDN Git Service

* decl.c (vtable_decl_p, vtype_decl_p, walk_globals_data,
[pf3gnuchains/gcc-fork.git] / gcc / cp / call.c
index 4e5b3d5..4828b9c 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to invoking methods and overloaded functions.
    Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
-   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com) and
    modified by Brendan Kehoe (brendan@cygnus.com).
 
@@ -92,6 +92,9 @@ struct conversion {
      copy constructor must be accessible, even though it is not being
      used.  */
   BOOL_BITFIELD check_copy_constructor_p : 1;
+  /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
+     from a pointer-to-derived to pointer-to-base is being performed.  */ 
+  BOOL_BITFIELD base_p : 1;
   /* The type of the expression resulting from the conversion.  */
   tree type;
   union {
@@ -125,12 +128,15 @@ static int compare_ics (conversion *, conversion *);
 static tree build_over_call (struct z_candidate *, int);
 static tree build_java_interface_fn_ref (tree, tree);
 #define convert_like(CONV, EXPR)                               \
-  convert_like_real ((CONV), (EXPR), NULL_TREE, 0, 0,          \
-                    /*issue_conversion_warnings=*/true)
+  convert_like_real ((CONV), (EXPR), NULL_TREE, 0, 0,          \
+                    /*issue_conversion_warnings=*/true,        \
+                    /*c_cast_p=*/false)
 #define convert_like_with_context(CONV, EXPR, FN, ARGNO)       \
-  convert_like_real ((CONV), (EXPR), (FN), (ARGNO), 0,                 \
-                    /*issue_conversion_warnings=*/true)
-static tree convert_like_real (conversion *, tree, tree, int, int, bool);
+  convert_like_real ((CONV), (EXPR), (FN), (ARGNO), 0,         \
+                    /*issue_conversion_warnings=*/true,        \
+                     /*c_cast_p=*/false)
+static tree convert_like_real (conversion *, tree, tree, int, int, bool,
+                              bool);
 static void op_error (enum tree_code, enum tree_code, tree, tree,
                            tree, const char *);
 static tree build_object_call (tree, tree);
@@ -164,7 +170,7 @@ static struct z_candidate *add_conv_candidate
 static struct z_candidate *add_function_candidate 
        (struct z_candidate **, tree, tree, tree, tree, tree, int);
 static conversion *implicit_conversion (tree, tree, tree, int);
-static conversion *standard_conversion (tree, tree, tree);
+static conversion *standard_conversion (tree, tree, tree, int);
 static conversion *reference_binding (tree, tree, tree, int);
 static conversion *build_conv (conversion_kind, tree, conversion *);
 static bool is_subseq (conversion *, conversion *);
@@ -191,23 +197,6 @@ static bool magic_varargs_p (tree);
 static tree build_temp (tree, tree, int, void (**)(const char *, ...));
 static void check_constructor_callable (tree, tree);
 
-tree
-build_vfield_ref (tree datum, tree type)
-{
-  if (datum == error_mark_node)
-    return error_mark_node;
-
-  if (TREE_CODE (TREE_TYPE (datum)) == REFERENCE_TYPE)
-    datum = convert_from_reference (datum);
-
-  if (TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (type)
-      && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
-    datum = convert_to_base (datum, type, /*check_access=*/false);
-
-  return build3 (COMPONENT_REF, TREE_TYPE (TYPE_VFIELD (type)),
-                datum, TYPE_VFIELD (type), NULL_TREE);
-}
-
 /* Returns nonzero iff the destructor name specified in NAME
    (a BIT_NOT_EXPR) matches BASETYPE.  The operand of NAME can take many
    forms...  */
@@ -439,8 +428,7 @@ null_ptr_cst_p (tree t)
 
      A null pointer constant is an integral constant expression
      (_expr.const_) rvalue of integer type that evaluates to zero.  */
-  if (DECL_INTEGRAL_CONSTANT_VAR_P (t))
-    t = decl_constant_value (t);
+  t = integral_constant_value (t);
   if (t == null_node
       || (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)) && integer_zerop (t)))
     return true;
@@ -545,6 +533,7 @@ build_conv (conversion_kind code, tree type, conversion *from)
   t->rank = rank;
   t->user_conv_p = (code == ck_user || from->user_conv_p);
   t->bad_p = from->bad_p;
+  t->base_p = false;
   return t;
 }
 
@@ -593,7 +582,7 @@ strip_top_quals (tree t)
    also pass the expression EXPR to convert from.  */
 
 static conversion *
-standard_conversion (tree to, tree from, tree expr)
+standard_conversion (tree to, tree from, tree expr, int flags)
 {
   enum tree_code fcode, tcode;
   conversion *conv;
@@ -643,7 +632,7 @@ standard_conversion (tree to, tree from, tree expr)
          the standard conversion sequence to perform componentwise
          conversion.  */
       conversion *part_conv = standard_conversion
-        (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE);
+        (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, flags);
       
       if (part_conv)
         {
@@ -662,11 +651,6 @@ standard_conversion (tree to, tree from, tree expr)
   if ((tcode == POINTER_TYPE || TYPE_PTR_TO_MEMBER_P (to))
       && expr && null_ptr_cst_p (expr))
     conv = build_conv (ck_std, to, conv);
-  else if (tcode == POINTER_TYPE && fcode == POINTER_TYPE
-          && TREE_CODE (TREE_TYPE (to)) == VECTOR_TYPE
-          && TREE_CODE (TREE_TYPE (from)) == VECTOR_TYPE
-          && vector_types_convertible_p (TREE_TYPE (to), TREE_TYPE (from)))
-    conv = build_conv (ck_std, to, conv);
   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
           || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
     {
@@ -728,9 +712,9 @@ standard_conversion (tree to, tree from, tree expr)
                  _class.derived_) of D.  If B is an inaccessible
                  (clause _class.access_) or ambiguous
                  (_class.member.lookup_) base class of D, a program
-                 that necessitates this conversion is ill-formed.  */
-              /* Therefore, we use DERIVED_FROM_P, and not
-                 ACCESSIBLY_UNIQUELY_DERIVED_FROM_P, in this test.  */
+                 that necessitates this conversion is ill-formed.
+                 Therefore, we use DERIVED_FROM_P, and do not check
+                 access or uniqueness.  */
               && DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from)))
        {
          from = 
@@ -738,6 +722,7 @@ standard_conversion (tree to, tree from, tree expr)
                                     cp_type_quals (TREE_TYPE (from)));
          from = build_pointer_type (from);
          conv = build_conv (ck_ptr, from, conv);
+         conv->base_p = true;
        }
 
       if (tcode == POINTER_TYPE)
@@ -788,6 +773,7 @@ standard_conversion (tree to, tree from, tree expr)
                                         TREE_CHAIN (TYPE_ARG_TYPES (fromfn)));
       from = build_ptrmemfunc_type (build_pointer_type (from));
       conv = build_conv (ck_pmem, from, conv);
+      conv->base_p = true;
     }
   else if (tcode == BOOLEAN_TYPE)
     {
@@ -828,7 +814,8 @@ standard_conversion (tree to, tree from, tree expr)
   else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
           && vector_types_convertible_p (from, to))
     return build_conv (ck_std, to, conv);
-  else if (IS_AGGR_TYPE (to) && IS_AGGR_TYPE (from)
+  else if (!(flags & LOOKUP_CONSTRUCTOR_CALLABLE)
+          && IS_AGGR_TYPE (to) && IS_AGGR_TYPE (from)
           && is_properly_derived_from (from, to))
     {
       if (conv->kind == ck_rvalue)
@@ -1240,7 +1227,7 @@ implicit_conversion (tree to, tree from, tree expr, int flags)
   if (TREE_CODE (to) == REFERENCE_TYPE)
     conv = reference_binding (to, from, expr, flags);
   else
-    conv = standard_conversion (to, from, expr);
+    conv = standard_conversion (to, from, expr, flags);
 
   if (conv)
     return conv;
@@ -2196,7 +2183,7 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
 
   if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
        || DECL_BASE_CONSTRUCTOR_P (tmpl))
-      && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (tmpl)))
+      && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
     args_without_in_chrg = TREE_CHAIN (args_without_in_chrg);
 
   i = fn_type_unification (tmpl, explicit_targs, targs,
@@ -2346,10 +2333,18 @@ any_strictly_viable (struct z_candidate *cands)
   return false;
 }
 
+/* OBJ is being used in an expression like "OBJ.f (...)".  In other
+   words, it is about to become the "this" pointer for a member
+   function call.  Take the address of the object.  */
+
 static tree
 build_this (tree obj)
 {
-  /* Fix this to work on non-lvalues.  */
+  /* In a template, we are only concerned about the type of the
+     expression, so we can take a shortcut.  */
+  if (processing_template_decl)
+    return build_address (obj);
+
   return build_unary_op (ADDR_EXPR, obj, 0);
 }
 
@@ -2617,7 +2612,7 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags)
     {
       if (flags & LOOKUP_COMPLAIN)
        {
-         error ("conversion from `%T' to `%T' is ambiguous",
+         error ("conversion from %qT to %qT is ambiguous",
                    fromtype, totype);
          print_z_candidates (candidates);
        }
@@ -2662,7 +2657,8 @@ build_user_type_conversion (tree totype, tree expr, int flags)
     {
       if (cand->second_conv->kind == ck_ambig)
        return error_mark_node;
-      return convert_from_reference (convert_like (cand->second_conv, expr));
+      expr = convert_like (cand->second_conv, expr);
+      return convert_from_reference (expr);
     }
   return NULL_TREE;
 }
@@ -2684,8 +2680,6 @@ resolve_args (tree args)
          error ("invalid use of void expression");
          return error_mark_node;
        }
-      arg = convert_from_reference (arg);
-      TREE_VALUE (t) = arg;
     }
   return args;
 }
@@ -2771,10 +2765,10 @@ build_new_function_call (tree fn, tree args)
       if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
        fn = TREE_OPERAND (fn, 0);
       if (!any_viable_p)
-       error ("no matching function for call to `%D(%A)'",
+       error ("no matching function for call to %<%D(%A)%>",
               DECL_NAME (OVL_CURRENT (fn)), args);
       else
-       error ("call of overloaded `%D(%A)' is ambiguous",
+       error ("call of overloaded %<%D(%A)%> is ambiguous",
               DECL_NAME (OVL_CURRENT (fn)), args);
       if (candidates)
        print_z_candidates (candidates);
@@ -2829,10 +2823,10 @@ build_operator_new_call (tree fnname, tree args, tree *size, tree *cookie_size)
   if (!cand)
     {
       if (!any_viable_p)
-       error ("no matching function for call to `%D(%A)'",
+       error ("no matching function for call to %<%D(%A)%>",
               DECL_NAME (OVL_CURRENT (fns)), args);
       else
-       error ("call of overloaded `%D(%A)' is ambiguous",
+       error ("call of overloaded %<%D(%A)%> is ambiguous",
               DECL_NAME (OVL_CURRENT (fns)), args);
       if (candidates)
        print_z_candidates (candidates);
@@ -2969,7 +2963,7 @@ build_object_call (tree obj, tree args)
   candidates = splice_viable (candidates, pedantic, &any_viable_p);
   if (!any_viable_p)
     {
-      error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj), args);
+      error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj), args);
       print_z_candidates (candidates);
       result = error_mark_node;
     }
@@ -2978,7 +2972,7 @@ build_object_call (tree obj, tree args)
       cand = tourney (candidates);
       if (cand == 0)
        {
-         error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj), args);
+         error ("call of %<(%T) (%A)%> is ambiguous", TREE_TYPE (obj), args);
          print_z_candidates (candidates);
          result = error_mark_node;
        }
@@ -2991,6 +2985,7 @@ build_object_call (tree obj, tree args)
       else
        {
          obj = convert_like_with_context (cand->convs[0], obj, cand->fn, -1);
+         obj = convert_from_reference (obj);
          result = build_function_call (obj, args);
        }
     }
@@ -3015,30 +3010,30 @@ op_error (enum tree_code code, enum tree_code code2,
   switch (code)
     {
     case COND_EXPR:
-      error ("%s for ternary 'operator?:' in '%E ? %E : %E'",
+      error ("%s for ternary %<operator?:%> in %<%E ? %E : %E%>",
              problem, arg1, arg2, arg3);
       break;
       
     case POSTINCREMENT_EXPR:
     case POSTDECREMENT_EXPR:
-      error ("%s for 'operator%s' in '%E%s'", problem, opname, arg1, opname);
+      error ("%s for %<operator%s%> in %<%E%s%>", problem, opname, arg1, opname);
       break;
       
     case ARRAY_REF:
-      error ("%s for 'operator[]' in '%E[%E]'", problem, arg1, arg2);
+      error ("%s for %<operator[]%> in %<%E[%E]%>", problem, arg1, arg2);
       break;
 
     case REALPART_EXPR:
     case IMAGPART_EXPR:
-      error ("%s for '%s' in '%s %E'", problem, opname, opname, arg1);
+      error ("%s for %qs in %<%s %E%>", problem, opname, opname, arg1);
       break;
       
     default:
       if (arg2)
-       error ("%s for 'operator%s' in '%E %s %E'",
+       error ("%s for %<operator%s%> in %<%E %s %E%>",
                problem, opname, arg1, opname, arg2);
       else
-       error ("%s for 'operator%s' in '%s%E'",
+       error ("%s for %<operator%s%> in %<%s%E%>",
                problem, opname, opname, arg1);
       break;
     }
@@ -3205,7 +3200,7 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
        result_type = void_type_node;
       else
        {
-         error ("`%E' has type `void' and is not a throw-expression",
+         error ("%qE has type %<void%> and is not a throw-expression",
                    VOID_TYPE_P (arg2_type) ? arg2 : arg3);
          return error_mark_node;
        }
@@ -3408,7 +3403,7 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
       
       if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
           && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
-         warning ("enumeral mismatch in conditional expression: `%T' vs `%T'",
+         warning ("enumeral mismatch in conditional expression: %qT vs %qT",
                    arg2_type, arg3_type);
       else if (extra_warnings
                && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
@@ -3459,7 +3454,8 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
     }
 
  valid_operands:
-  result = fold (build3 (COND_EXPR, result_type, arg1, arg2, arg3));
+  result = fold_if_not_in_template (build3 (COND_EXPR, result_type, arg1, 
+                                           arg2, arg3));
   /* We can't use result_type below, as fold might have returned a
      throw_expr.  */
 
@@ -3486,7 +3482,6 @@ prep_operand (tree operand)
 {
   if (operand)
     {
-      operand = convert_from_reference (operand);
       if (CLASS_TYPE_P (TREE_TYPE (operand))
          && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
        /* Make sure the template type is instantiated now.  */
@@ -3709,9 +3704,10 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
          /* Look for an `operator++ (int)'.  If they didn't have
             one, then we fall back to the old way of doing things.  */
          if (flags & LOOKUP_COMPLAIN)
-           pedwarn ("no `%D(int)' declared for postfix `%s', trying prefix operator instead",
-                       fnname, 
-                       operator_name_info[code].name);
+           pedwarn ("no %<%D(int)%> declared for postfix %qs, "
+                     "trying prefix operator instead",
+                     fnname, 
+                     operator_name_info[code].name);
          if (code == POSTINCREMENT_EXPR)
            code = PREINCREMENT_EXPR;
          else
@@ -3761,9 +3757,9 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
              && candidates->next
              && ! candidates->next->next)
            {
-             warning ("using synthesized `%#D' for copy assignment",
+             warning ("using synthesized %q#D for copy assignment",
                          cand->fn);
-             cp_warning_at ("  where cfront would use `%#D'",
+             cp_warning_at ("  where cfront would use %q#D",
                             cand == candidates
                             ? candidates->next->fn
                             : candidates->fn);
@@ -3795,8 +3791,8 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
                  && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1))
                      != TYPE_MAIN_VARIANT (TREE_TYPE (arg2))))
                {
-                 warning ("comparison between `%#T' and `%#T'", 
-                             TREE_TYPE (arg1), TREE_TYPE (arg2));
+                 warning ("comparison between %q#T and %q#T", 
+                           TREE_TYPE (arg1), TREE_TYPE (arg2));
                }
              break;
            default:
@@ -4052,7 +4048,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
   if (placement)
     return NULL_TREE;
 
-  error ("no suitable `operator %s' for `%T'",
+  error ("no suitable %<operator %s> for %qT",
         operator_name_info[(int)code].name, type);
   return error_mark_node;
 }
@@ -4066,14 +4062,14 @@ enforce_access (tree basetype_path, tree decl)
 {
   gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
   
-  if (!accessible_p (basetype_path, decl))
+  if (!accessible_p (basetype_path, decl, true))
     {
       if (TREE_PRIVATE (decl))
-       cp_error_at ("`%+#D' is private", decl);
+       cp_error_at ("%q+#D is private", decl);
       else if (TREE_PROTECTED (decl))
-       cp_error_at ("`%+#D' is protected", decl);
+       cp_error_at ("%q+#D is protected", decl);
       else
-       cp_error_at ("`%+#D' is inaccessible", decl);
+       cp_error_at ("%q+#D is inaccessible", decl);
       error ("within this context");
       return false;
     }
@@ -4092,6 +4088,7 @@ check_constructor_callable (tree type, tree expr)
                             build_tree_list (NULL_TREE, expr), 
                             type,
                             LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING
+                            | LOOKUP_NO_CONVERSION
                             | LOOKUP_CONSTRUCTOR_CALLABLE);
 }
 
@@ -4128,11 +4125,14 @@ build_temp (tree expr, tree type, int flags,
    being called to continue a conversion chain. It is negative when a
    reference binding will be applied, positive otherwise.  If
    ISSUE_CONVERSION_WARNINGS is true, warnings about suspicious
-   conversions will be emitted if appropriate.  */
+   conversions will be emitted if appropriate.  If C_CAST_P is true,
+   this conversion is coming from a C-style cast; in that case,
+   conversions to inaccessible bases are permitted.  */
 
 static tree
 convert_like_real (conversion *convs, tree expr, tree fn, int argnum, 
-                  int inner, bool issue_conversion_warnings)
+                  int inner, bool issue_conversion_warnings,
+                  bool c_cast_p)
 {
   tree totype = convs->type;
   void (*diagnostic_fn)(const char *, ...);
@@ -4148,18 +4148,20 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
          if (t->kind == ck_user || !t->bad_p)
            {
              expr = convert_like_real (t, expr, fn, argnum, 1,
-                                       /*issue_conversion_warnings=*/false);
+                                       /*issue_conversion_warnings=*/false,
+                                       /*c_cast_p=*/false);
              break;
            }
          else if (t->kind == ck_ambig)
            return convert_like_real (t, expr, fn, argnum, 1,
-                                     /*issue_conversion_warnings=*/false);
+                                     /*issue_conversion_warnings=*/false,
+                                     /*c_cast_p=*/false);
          else if (t->kind == ck_identity)
            break;
        }
-      pedwarn ("invalid conversion from `%T' to `%T'", TREE_TYPE (expr), totype);
+      pedwarn ("invalid conversion from %qT to %qT", TREE_TYPE (expr), totype);
       if (fn)
-       pedwarn ("  initializing argument %P of `%D'", argnum, fn);
+       pedwarn ("  initializing argument %P of %qD", argnum, fn);
       return cp_convert (totype, expr);
     }
   
@@ -4219,11 +4221,11 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
              {
                if (fn)
                  diagnostic_fn 
-                   ("  initializing argument %P of `%D' from result of `%D'",
+                   ("  initializing argument %P of %qD from result of %qD",
                     argnum, fn, convfn);
                else
                 diagnostic_fn 
-                  ("  initializing temporary from result of `%D'",  convfn);
+                  ("  initializing temporary from result of %qD",  convfn);
              }
            expr = build_cplus_new (totype, expr);
          }
@@ -4232,15 +4234,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
     case ck_identity:
       if (type_unknown_p (expr))
        expr = instantiate_type (totype, expr, tf_error | tf_warning);
-      /* Convert a non-array constant variable to its underlying value, unless we
-        are about to bind it to a reference, in which case we need to
+      /* Convert a constant to its underlying value, unless we are
+        about to bind it to a reference, in which case we need to
         leave it as an lvalue.  */
-      if (inner >= 0
-         && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
-       expr = decl_constant_value (expr);
+      if (inner >= 0)
+       expr = integral_constant_value (expr);
       if (convs->check_copy_constructor_p)
        check_constructor_callable (totype, expr);
-       return expr;
+      return expr;
     case ck_ambig:
       /* Call build_user_type_conversion again for the error.  */
       return build_user_type_conversion
@@ -4252,7 +4253,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 
   expr = convert_like_real (convs->u.next, expr, fn, argnum,
                            convs->kind == ck_ref_bind ? -1 : 1,
-                           /*issue_conversion_warnings=*/false);
+                           /*issue_conversion_warnings=*/false,
+                           c_cast_p);
   if (expr == error_mark_node)
     return error_mark_node;
 
@@ -4271,8 +4273,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
            check_constructor_callable (TREE_TYPE (expr), expr);
          /* Build an expression for `*((base*) &expr)'.  */
          expr = build_unary_op (ADDR_EXPR, expr, 0);
-         expr = perform_implicit_conversion (build_pointer_type (totype), 
-                                             expr);
+         expr = convert_to_base (expr, build_pointer_type (totype),
+                                 !c_cast_p, /*nonnull=*/true);
          expr = build_indirect_ref (expr, "implicit conversion");
          return expr;
        }
@@ -4283,7 +4285,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
       expr = build_temp (expr, totype, LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING,
                         &diagnostic_fn);
       if (diagnostic_fn && fn)
-       diagnostic_fn ("  initializing argument %P of `%D'", argnum, fn);
+       diagnostic_fn ("  initializing argument %P of %qD", argnum, fn);
       return build_cplus_new (totype, expr);
 
     case ck_ref_bind:
@@ -4294,21 +4296,34 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
        if (convs->need_temporary_p || !lvalue_p (expr))
          {
            tree type = convs->u.next->type;
+           cp_lvalue_kind lvalue = real_lvalue_p (expr);
 
            if (!CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
              {
                /* If the reference is volatile or non-const, we
                   cannot create a temporary.  */
-               cp_lvalue_kind lvalue = real_lvalue_p (expr);
-               
                if (lvalue & clk_bitfield)
-                 error ("cannot bind bitfield `%E' to `%T'",
+                 error ("cannot bind bitfield %qE to %qT",
                         expr, ref_type);
                else if (lvalue & clk_packed)
-                 error ("cannot bind packed field `%E' to `%T'",
+                 error ("cannot bind packed field %qE to %qT",
                         expr, ref_type);
                else
-                 error ("cannot bind rvalue `%E' to `%T'", expr, ref_type);
+                 error ("cannot bind rvalue %qE to %qT", expr, ref_type);
+               return error_mark_node;
+             }
+           /* If the source is a packed field, and we must use a copy
+              constructor, then building the target expr will require
+              binding the field to the reference parameter to the
+              copy constructor, and we'll end up with an infinite
+              loop.  If we can use a bitwise copy, then we'll be
+              OK.  */
+           if ((lvalue & clk_packed) 
+               && CLASS_TYPE_P (type) 
+               && !TYPE_HAS_TRIVIAL_INIT_REF (type))
+             {
+               error ("cannot bind packed field %qE to %qT",
+                      expr, ref_type);
                return error_mark_node;
              }
            expr = build_target_expr_with_type (expr, type);
@@ -4336,7 +4351,17 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
       /* Warn about deprecated conversion if appropriate.  */
       string_conv_p (totype, expr, 1);
       break;
-      
+
+    case ck_ptr:
+      if (convs->base_p)
+       expr = convert_to_base (expr, totype, !c_cast_p,
+                               /*nonnull=*/false);
+      return build_nop (totype, expr);
+
+    case ck_pmem:
+      return convert_ptrmem (totype, expr, /*allow_inverse_p=*/false,
+                            c_cast_p);
+
     default:
       break;
     }
@@ -4393,7 +4418,7 @@ convert_arg_to_ellipsis (tree arg)
         there is no need to emit a warning, since the expression won't be 
         evaluated. We keep the builtin_trap just as a safety check.  */
       if (!skip_evaluation)
-       warning ("cannot pass objects of non-POD type `%#T' through `...'; "
+       warning ("cannot pass objects of non-POD type %q#T through %<...%>; "
                 "call will abort at runtime", TREE_TYPE (arg));
       arg = call_builtin_trap ();
       arg = build2 (COMPOUND_EXPR, integer_type_node, arg,
@@ -4419,9 +4444,8 @@ build_x_va_arg (tree expr, tree type)
   if (! pod_type_p (type))
     {
       /* Undefined behavior [expr.call] 5.2.2/7.  */
-      warning ("cannot receive objects of non-POD type `%#T' through `...'; \
-call will abort at runtime",
-              type);
+      warning ("cannot receive objects of non-POD type %q#T through %<...%>; "
+               "call will abort at runtime", type);
       expr = convert (build_pointer_type (type), null_node);
       expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
                     call_builtin_trap (), expr);
@@ -4463,7 +4487,7 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum)
      conversion cannot be performed.  */
   if (TREE_CODE (arg) == DEFAULT_ARG)
     {
-      error ("the default argument for parameter %d of `%D' has "
+      error ("the default argument for parameter %d of %qD has "
             "not yet been parsed",
             parmnum, fn);
       return error_mark_node;
@@ -4630,7 +4654,7 @@ build_over_call (struct z_candidate *cand, int flags)
         primary template because `B<T>::g' and `B<int>::g' may have
         different access.  */
       if (DECL_TEMPLATE_INFO (fn)
-         && is_member_template (DECL_TI_TEMPLATE (fn)))
+         && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
        perform_or_defer_access_check (cand->access_path,
                                       DECL_TI_TEMPLATE (fn));
       else
@@ -4668,8 +4692,8 @@ build_over_call (struct z_candidate *cand, int flags)
       tree base_binfo;
       
       if (convs[i]->bad_p)
-       pedwarn ("passing `%T' as `this' argument of `%#D' discards qualifiers",
-                   TREE_TYPE (argtype), fn);
+       pedwarn ("passing %qT as %<this%> argument of %q#D discards qualifiers",
+                 TREE_TYPE (argtype), fn);
 
       /* [class.mfct.nonstatic]: If a nonstatic member function of a class
         X is called for an object that is not of type X, or of a type
@@ -4686,15 +4710,15 @@ build_over_call (struct z_candidate *cand, int flags)
                                       1);
       /* Check that the base class is accessible.  */
       if (!accessible_base_p (TREE_TYPE (argtype), 
-                             BINFO_TYPE (cand->conversion_path)))
-       error ("`%T' is not an accessible base of `%T'",
+                             BINFO_TYPE (cand->conversion_path), true))
+       error ("%qT is not an accessible base of %qT",
               BINFO_TYPE (cand->conversion_path),
               TREE_TYPE (argtype));
       /* If fn was found by a using declaration, the conversion path
          will be to the derived class, not the base declaring fn. We
          must convert from derived to base.  */
       base_binfo = lookup_base (TREE_TYPE (TREE_TYPE (converted_arg)),
-                               TREE_TYPE (parmtype), ba_ignore, NULL);
+                               TREE_TYPE (parmtype), ba_unique, NULL);
       converted_arg = build_base_path (PLUS_EXPR, converted_arg,
                                       base_binfo, 1);
       
@@ -4886,7 +4910,7 @@ build_cxx_call (tree fn, tree args)
 
   /* Some built-in function calls will be evaluated at compile-time in
      fold ().  */
-  fn = fold (fn);
+  fn = fold_if_not_in_template (fn);
 
   if (VOID_TYPE_P (TREE_TYPE (fn)))
     return fn;
@@ -4937,7 +4961,7 @@ build_java_interface_fn_ref (tree fn, tree instance)
   if (!iface_ref || TREE_CODE (iface_ref) != VAR_DECL
       || DECL_CONTEXT (iface_ref) != iface)
     {
-      error ("could not find class$ field in java interface type `%T'", 
+      error ("could not find class$ field in java interface type %qT", 
                iface);
       return error_mark_node;
     }
@@ -5069,7 +5093,7 @@ build_special_member_call (tree instance, tree name, tree args,
      the subobject.  */
   if ((name == base_ctor_identifier
        || name == base_dtor_identifier)
-      && TYPE_USES_VIRTUAL_BASECLASSES (class_type))
+      && CLASSTYPE_VBASECLASSES (class_type))
     {
       tree vtt;
       tree sub_vtt;
@@ -5192,14 +5216,12 @@ build_new_method_call (tree instance, tree fns, tree args,
   if (args == error_mark_node)
     return error_mark_node;
 
-  if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
-    instance = convert_from_reference (instance);
   basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
   instance_ptr = build_this (instance);
 
   if (!BASELINK_P (fns))
     {
-      error ("call to non-function `%D'", fns);
+      error ("call to non-function %qD", fns);
       return error_mark_node;
     }
 
@@ -5224,7 +5246,8 @@ build_new_method_call (tree instance, tree fns, tree args,
   if (! IS_AGGR_TYPE (basetype))
     {
       if ((flags & LOOKUP_COMPLAIN) && basetype != error_mark_node)
-       error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
+       error ("request for member %qD in %qE, which is of non-aggregate "
+               "type %qT",
               fns, instance, basetype);
 
       return error_mark_node;
@@ -5302,7 +5325,7 @@ build_new_method_call (tree instance, tree fns, tree args,
          bool free_p;
 
          pretty_name = name_as_c_string (name, basetype, &free_p);
-         error ("no matching function for call to `%T::%s(%A)%#V'",
+         error ("no matching function for call to %<%T::%s(%A)%#V%>",
                 basetype, pretty_name, user_args,
                 TREE_TYPE (TREE_TYPE (instance_ptr)));
          if (free_p)
@@ -5320,7 +5343,7 @@ build_new_method_call (tree instance, tree fns, tree args,
          bool free_p;
 
          pretty_name = name_as_c_string (name, basetype, &free_p);
-         error ("call of overloaded `%s(%A)' is ambiguous", pretty_name,
+         error ("call of overloaded %<%s(%A)%> is ambiguous", pretty_name,
                 user_args);
          print_z_candidates (candidates);
          if (free_p)
@@ -5329,20 +5352,22 @@ build_new_method_call (tree instance, tree fns, tree args,
        }
       else
        {
-         if (DECL_PURE_VIRTUAL_P (cand->fn)
+         if (!(flags & LOOKUP_NONVIRTUAL)
+             && DECL_PURE_VIRTUAL_P (cand->fn)
              && instance == current_class_ref
              && (DECL_CONSTRUCTOR_P (current_function_decl)
-                 || DECL_DESTRUCTOR_P (current_function_decl))
-             && ! (flags & LOOKUP_NONVIRTUAL)
-             && value_member (cand->fn, CLASSTYPE_PURE_VIRTUALS (basetype)))
-           error ((DECL_CONSTRUCTOR_P (current_function_decl) ? 
-                   "abstract virtual `%#D' called from constructor"
-                   : "abstract virtual `%#D' called from destructor"),
-                  cand->fn);
+                 || DECL_DESTRUCTOR_P (current_function_decl)))
+           /* This is not an error, it is runtime undefined
+              behavior.  */
+           warning ((DECL_CONSTRUCTOR_P (current_function_decl) ? 
+                     "abstract virtual %q#D called from constructor"
+                     : "abstract virtual %q#D called from destructor"),
+                    cand->fn);
+         
          if (TREE_CODE (TREE_TYPE (cand->fn)) == METHOD_TYPE
              && is_dummy_object (instance_ptr))
            {
-             error ("cannot call member function `%D' without object", 
+             error ("cannot call member function %qD without object", 
                     cand->fn);
              call = error_mark_node;
            }
@@ -5882,7 +5907,7 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
   /* If we have two pseudo-candidates for conversions to the same type,
      or two candidates for the same function, arbitrarily pick one.  */
   if (cand1->fn == cand2->fn
-      && (TYPE_P (cand1->fn) || DECL_P (cand1->fn)))
+      && (IS_TYPE_OR_DECL_P (cand1->fn)))
     return 1;
 
   /* a viable function F1
@@ -5947,9 +5972,9 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
 
              if (warn)
                {
-                 warning ("passing `%T' chooses `%T' over `%T'",
+                 warning ("passing %qT chooses %qT over %qT",
                              type, type1, type2);
-                 warning ("  in call to `%D'", w->fn);
+                 warning ("  in call to %qD", w->fn);
                }
              else
                add_warning (w, l);
@@ -6006,8 +6031,8 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
          tree source = source_type (w->convs[0]);
          if (! DECL_CONSTRUCTOR_P (w->fn))
            source = TREE_TYPE (source);
-         warning ("choosing `%D' over `%D'", w->fn, l->fn);
-         warning ("  for conversion from `%T' to `%T'",
+         warning ("choosing %qD over %qD", w->fn, l->fn);
+         warning ("  for conversion from %qT to %qT",
                   source, w->second_conv->type);
          warning ("  because conversion sequence for the argument is better");
        }
@@ -6271,7 +6296,7 @@ perform_implicit_conversion (tree type, tree expr)
                              LOOKUP_NORMAL);
   if (!conv)
     {
-      error ("could not convert `%E' to `%T'", expr, type);
+      error ("could not convert %qE to %qT", expr, type);
       expr = error_mark_node;
     }
   else
@@ -6286,10 +6311,15 @@ perform_implicit_conversion (tree type, tree expr)
 /* Convert EXPR to TYPE (as a direct-initialization) if that is
    permitted.  If the conversion is valid, the converted expression is
    returned.  Otherwise, NULL_TREE is returned, except in the case
-   that TYPE is a class type; in that case, an error is issued.  */
+   that TYPE is a class type; in that case, an error is issued.  If
+   C_CAST_P is true, then this direction initialization is taking
+   place as part of a static_cast being attempted as part of a C-style
+   cast.  */
 
 tree
-perform_direct_initialization_if_possible (tree type, tree expr)
+perform_direct_initialization_if_possible (tree type, 
+                                          tree expr,
+                                          bool c_cast_p)
 {
   conversion *conv;
   void *p;
@@ -6321,7 +6351,8 @@ perform_direct_initialization_if_possible (tree type, tree expr)
     expr = NULL_TREE;
   else
     expr = convert_like_real (conv, expr, NULL_TREE, 0, 0, 
-                             /*issue_conversion_warnings=*/false);
+                             /*issue_conversion_warnings=*/false,
+                             c_cast_p);
 
   /* Free all the conversions we allocated.  */
   obstack_free (&conversion_obstack, p);
@@ -6342,6 +6373,7 @@ make_temporary_var_for_ref_to_temp (tree decl, tree type)
   /* Create the variable.  */
   var = build_decl (VAR_DECL, NULL_TREE, type);
   DECL_ARTIFICIAL (var) = 1;
+  DECL_IGNORED_P (var) = 1;
   TREE_USED (var) = 1;
 
   /* Register the variable.  */
@@ -6396,11 +6428,11 @@ initialize_reference (tree type, tree expr, tree decl, tree *cleanup)
       if (!(TYPE_QUALS (TREE_TYPE (type)) & TYPE_QUAL_CONST)
           && !real_lvalue_p (expr))
         error ("invalid initialization of non-const reference of "
-               "type '%T' from a temporary of type '%T'",
+               "type %qT from a temporary of type %qT",
                type, TREE_TYPE (expr));
       else
         error ("invalid initialization of reference of type "
-              "'%T' from expression of type '%T'", type, 
+              "%qT from expression of type %qT", type, 
               TREE_TYPE (expr));
       return error_mark_node;
     }
@@ -6449,7 +6481,7 @@ initialize_reference (tree type, tree expr, tree decl, tree *cleanup)
       conv = conv->u.next;
       /* If the next conversion is a BASE_CONV, skip that too -- but
         remember that the conversion was required.  */
-      if (conv->kind == ck_base && conv->need_temporary_p)
+      if (conv->kind == ck_base)
        {
          if (conv->check_copy_constructor_p)
            check_constructor_callable (TREE_TYPE (expr), expr);
@@ -6462,7 +6494,8 @@ initialize_reference (tree type, tree expr, tree decl, tree *cleanup)
       expr = convert_like_real (conv, expr,
                                /*fn=*/NULL_TREE, /*argnum=*/0,
                                /*inner=*/-1,
-                               /*issue_conversion_warnings=*/true);
+                               /*issue_conversion_warnings=*/true,
+                               /*c_cast_p=*/false);
       if (!real_lvalue_p (expr))
        {
          tree init;
@@ -6518,6 +6551,11 @@ initialize_reference (tree type, tree expr, tree decl, tree *cleanup)
            }
          /* Use its address to initialize the reference variable.  */
          expr = build_address (var);
+         if (base_conv_type)
+           expr = convert_to_base (expr, 
+                                   build_pointer_type (base_conv_type),
+                                   /*check_access=*/true,
+                                   /*nonnull=*/true);
          expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), init, expr);
        }
       else