/* 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).
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 {
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);
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 *);
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... */
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;
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;
}
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;
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)
{
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))
{
_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 =
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)
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)
{
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)
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;
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,
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);
}
{
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);
}
{
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;
}
error ("invalid use of void expression");
return error_mark_node;
}
- arg = convert_from_reference (arg);
- TREE_VALUE (t) = arg;
}
return 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);
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);
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;
}
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;
}
else
{
obj = convert_like_with_context (cand->convs[0], obj, cand->fn, -1);
+ obj = convert_from_reference (obj);
result = build_function_call (obj, args);
}
}
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;
}
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;
}
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
}
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. */
{
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. */
/* 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
&& 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);
&& (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:
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;
}
{
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;
}
build_tree_list (NULL_TREE, expr),
type,
LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING
+ | LOOKUP_NO_CONVERSION
| LOOKUP_CONSTRUCTOR_CALLABLE);
}
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 *, ...);
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);
}
{
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);
}
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
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;
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;
}
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:
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);
/* 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;
}
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,
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);
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;
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
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
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);
/* 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;
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;
}
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;
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;
}
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;
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)
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)
}
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;
}
/* 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
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);
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");
}
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
/* 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;
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);
/* 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. */
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;
}
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);
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;
}
/* 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