Commit 3f55e16a by Jason Merrill Committed by Jason Merrill

call.c (maybe_print_user_conv_context): New.

	* call.c (maybe_print_user_conv_context): New.
	(convert_like_real): Use it.  Print call context for bad
	user-defined conversion.
	(build_over_call): Print call context for bad 'this' conversion.

From-SVN: r210350
parent eed64f27
2014-05-12 Jason Merrill <jason@redhat.com> 2014-05-12 Jason Merrill <jason@redhat.com>
* call.c (maybe_print_user_conv_context): New.
(convert_like_real): Use it. Print call context for bad
user-defined conversion.
(build_over_call): Print call context for bad 'this' conversion.
* call.c (convert_like_real): Use inform for identifying the * call.c (convert_like_real): Use inform for identifying the
declaration point. declaration point.
......
...@@ -5942,6 +5942,23 @@ conversion_null_warnings (tree totype, tree expr, tree fn, int argnum) ...@@ -5942,6 +5942,23 @@ conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
} }
} }
/* We gave a diagnostic during a conversion. If this was in the second
standard conversion sequence of a user-defined conversion sequence, say
which user-defined conversion. */
static void
maybe_print_user_conv_context (conversion *convs)
{
if (convs->user_conv_p)
for (conversion *t = convs; t; t = next_conversion (t))
if (t->kind == ck_user)
{
print_z_candidate (0, " after user-defined conversion:",
t->cand);
break;
}
}
/* Perform the conversions in CONVS on the expression EXPR. FN and /* Perform the conversions in CONVS on the expression EXPR. FN and
ARGNUM are used for diagnostics. ARGNUM is zero based, -1 ARGNUM are used for diagnostics. ARGNUM is zero based, -1
indicates the `this' argument of a method. INNER is nonzero when indicates the `this' argument of a method. INNER is nonzero when
...@@ -6003,11 +6020,15 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6003,11 +6020,15 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
/*c_cast_p=*/false, /*c_cast_p=*/false,
complain); complain);
if (convs->kind == ck_ref_bind) if (convs->kind == ck_ref_bind)
return convert_to_reference (totype, expr, CONV_IMPLICIT, expr = convert_to_reference (totype, expr, CONV_IMPLICIT,
LOOKUP_NORMAL, NULL_TREE, LOOKUP_NORMAL, NULL_TREE,
complain); complain);
else else
return cp_convert (totype, expr, complain); expr = cp_convert (totype, expr, complain);
if (fn)
inform (DECL_SOURCE_LOCATION (fn),
" initializing argument %P of %qD", argnum, fn);
return expr;
} }
else if (t->kind == ck_user || !t->bad_p) else if (t->kind == ck_user || !t->bad_p)
{ {
...@@ -6030,7 +6051,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6030,7 +6051,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
TREE_TYPE (expr), totype); TREE_TYPE (expr), totype);
if (complained && fn) if (complained && fn)
inform (DECL_SOURCE_LOCATION (fn), inform (DECL_SOURCE_LOCATION (fn),
"initializing argument %P of %qD", argnum, fn); " initializing argument %P of %qD", argnum, fn);
return cp_convert (totype, expr, complain); return cp_convert (totype, expr, complain);
} }
...@@ -6135,7 +6156,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6135,7 +6156,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL, build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL,
complain); complain);
if (fn) if (fn)
inform (input_location, "initializing argument %P of %q+D", inform (input_location, " initializing argument %P of %q+D",
argnum, fn); argnum, fn);
} }
return error_mark_node; return error_mark_node;
...@@ -6255,9 +6276,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6255,9 +6276,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
/* Copy-list-initialization doesn't actually involve a copy. */ /* Copy-list-initialization doesn't actually involve a copy. */
return expr; return expr;
expr = build_temp (expr, totype, flags, &diag_kind, complain); expr = build_temp (expr, totype, flags, &diag_kind, complain);
if (diag_kind && fn && complain) if (diag_kind && complain)
inform (DECL_SOURCE_LOCATION (fn), {
" initializing argument %P of %qD", argnum, fn); maybe_print_user_conv_context (convs);
if (fn)
inform (DECL_SOURCE_LOCATION (fn),
" initializing argument %P of %qD", argnum, fn);
}
return build_cplus_new (totype, expr, complain); return build_cplus_new (totype, expr, complain);
case ck_ref_bind: case ck_ref_bind:
...@@ -6272,9 +6298,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6272,9 +6298,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
error_at (loc, "cannot bind %qT lvalue to %qT", error_at (loc, "cannot bind %qT lvalue to %qT",
TREE_TYPE (expr), totype); TREE_TYPE (expr), totype);
maybe_print_user_conv_context (convs);
if (fn) if (fn)
inform (input_location, inform (input_location,
"initializing argument %P of %q+D", argnum, fn); " initializing argument %P of %q+D", argnum, fn);
return error_mark_node; return error_mark_node;
} }
...@@ -6935,8 +6962,12 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) ...@@ -6935,8 +6962,12 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
if (convs[i]->bad_p) if (convs[i]->bad_p)
{ {
if (complain & tf_error) if (complain & tf_error)
permerror (input_location, "passing %qT as %<this%> argument of %q#D discards qualifiers", {
TREE_TYPE (argtype), fn); if (permerror (input_location, "passing %qT as %<this%> "
"argument discards qualifiers",
TREE_TYPE (argtype)))
inform (DECL_SOURCE_LOCATION (fn), " in call to %qD", fn);
}
else else
return error_mark_node; return error_mark_node;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment