aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/call.cc')
-rw-r--r--gcc/cp/call.cc58
1 files changed, 42 insertions, 16 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 37ad0a9..9283d97 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -220,7 +220,8 @@ static void add_candidates (tree, tree, const vec<tree, va_gc> *, tree, tree,
bool, tree, tree, int, struct z_candidate **,
tsubst_flags_t);
static conversion *merge_conversion_sequences (conversion *, conversion *);
-static tree build_temp (tree, tree, int, diagnostic_t *, tsubst_flags_t);
+static tree build_temp (tree, tree, int, enum diagnostics::kind *,
+ tsubst_flags_t);
static conversion *build_identity_conv (tree, tree);
static inline bool conv_binds_to_array_of_unknown_bound (conversion *);
static bool conv_is_prvalue (conversion *);
@@ -4927,6 +4928,11 @@ implicit_conversion_error (location_t loc, tree type, tree expr)
&& !CP_AGGREGATE_TYPE_P (type))
error_at (loc, "designated initializers cannot be used with a "
"non-aggregate type %qT", type);
+ else if (is_stub_object (expr))
+ /* The expression is generated by a trait check, we don't have
+ a useful location to highlight the label. */
+ error_at (loc, "could not convert %qH to %qI",
+ TREE_TYPE (expr), type);
else
{
range_label_for_type_mismatch label (TREE_TYPE (expr), type);
@@ -6455,7 +6461,9 @@ build_conditional_expr (const op_location_t &loc,
types when the enumeration is still being defined. */;
else if (complain & (cxx_dialect >= cxx26
? tf_warning_or_error : tf_warning))
- emit_diagnostic (cxx_dialect >= cxx26 ? DK_PEDWARN : DK_WARNING,
+ emit_diagnostic ((cxx_dialect >= cxx26
+ ? diagnostics::kind::pedwarn
+ : diagnostics::kind::warning),
loc, OPT_Wenum_compare, "enumerated mismatch "
"in conditional expression: %qT vs %qT",
arg2_type, arg3_type);
@@ -7486,7 +7494,16 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags,
else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
{
if (overload)
- *overload = cand->fn;
+ {
+ if (cand->rewritten ())
+ /* build_min_non_dep_op_overload needs to know whether the
+ candidate is rewritten/reversed. */
+ *overload = build_tree_list (build_int_cst (integer_type_node,
+ cand->flags),
+ cand->fn);
+ else
+ *overload = cand->fn;
+ }
if (resolve_args (arglist, complain) == NULL)
result = error_mark_node;
@@ -7535,9 +7552,6 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags,
/* If this was a C++20 rewritten comparison, adjust the result. */
if (cand->rewritten ())
{
- /* FIXME build_min_non_dep_op_overload can't handle rewrites. */
- if (overload)
- *overload = NULL_TREE;
switch (code)
{
case EQ_EXPR:
@@ -7636,8 +7650,9 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags,
&& (complain & tf_warning_or_error) == 0)
result = error_mark_node;
else if (cxx_dialect >= cxx26 || (complain & tf_warning))
- emit_diagnostic (cxx_dialect >= cxx26
- ? DK_PEDWARN : DK_WARNING,
+ emit_diagnostic ((cxx_dialect >= cxx26
+ ? diagnostics::kind::pedwarn
+ : diagnostics::kind::warning),
loc, OPT_Wenum_compare,
"comparison between %q#T and %q#T",
arg1_type, arg2_type);
@@ -8451,11 +8466,11 @@ complain_about_access (tree decl, tree diag_decl, tree diag_location,
static tree
build_temp (tree expr, tree type, int flags,
- diagnostic_t *diagnostic_kind, tsubst_flags_t complain)
+ enum diagnostics::kind *diagnostic_kind, tsubst_flags_t complain)
{
int savew, savee;
- *diagnostic_kind = DK_UNSPECIFIED;
+ *diagnostic_kind = diagnostics::kind::unspecified;
/* If the source is a packed field, calling the copy constructor will require
binding the field to the reference parameter to the copy constructor, and
@@ -8479,9 +8494,9 @@ build_temp (tree expr, tree type, int flags,
expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
&args, type, flags, complain);
if (warningcount + werrorcount > savew)
- *diagnostic_kind = DK_WARNING;
+ *diagnostic_kind = diagnostics::kind::warning;
else if (errorcount > savee)
- *diagnostic_kind = DK_ERROR;
+ *diagnostic_kind = diagnostics::kind::error;
return expr;
}
@@ -8693,9 +8708,10 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
bool nested_p, tsubst_flags_t complain)
{
tree totype = convs->type;
- diagnostic_t diag_kind;
+ enum diagnostics::kind diag_kind;
int flags;
location_t loc = cp_expr_loc_or_input_loc (expr);
+ const bool stub_object_p = is_stub_object (expr);
if (convs->bad_p && !(complain & tf_error))
return error_mark_node;
@@ -8772,7 +8788,10 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
"from %qH to %qI", TREE_TYPE (expr),
totype);
if (complained)
- print_z_candidate (loc, N_("candidate is:"), t->cand);
+ {
+ auto_diagnostic_nesting_level sentinel;
+ print_z_candidate (loc, N_("candidate is:"), t->cand);
+ }
expr = convert_like (t, expr, fn, argnum,
/*issue_conversion_warnings=*/false,
/*c_cast_p=*/false, /*nested_p=*/true,
@@ -8797,7 +8816,14 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
else if (t->kind == ck_identity)
break;
}
- if (!complained && expr != error_mark_node)
+ if (!complained && stub_object_p)
+ {
+ /* An error diagnosed within a trait, don't give extra labels. */
+ error_at (loc, "invalid conversion from %qH to %qI",
+ TREE_TYPE (expr), totype);
+ complained = 1;
+ }
+ else if (!complained && expr != error_mark_node)
{
range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
gcc_rich_location richloc (loc, &label, highlight_colors::percent_h);
@@ -9220,7 +9246,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
if (convs->copy_init_p)
flags |= LOOKUP_ONLYCONVERTING;
expr = build_temp (expr, totype, flags, &diag_kind, complain);
- if (diag_kind && complain)
+ if (diag_kind != diagnostics::kind::unspecified && complain)
{
auto_diagnostic_group d;
maybe_print_user_conv_context (convs);