diff options
Diffstat (limited to 'gcc/cp/call.cc')
-rw-r--r-- | gcc/cp/call.cc | 109 |
1 files changed, 93 insertions, 16 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 2c3ef3d..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 *); @@ -412,6 +413,7 @@ build_call_a (tree function, int n, tree *argarray) /* We're disconnecting the initializer from its target, don't create a temporary. */ arg = TARGET_EXPR_INITIAL (arg); + suppress_warning (arg, OPT_Wunused_result); tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg)); arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t); CALL_EXPR_ARG (function, i) = arg; @@ -1723,6 +1725,56 @@ involves_qualification_conversion_p (tree to, tree from) return false; } +/* Return true if HANDLER is a match for exception object with EXCEPT_TYPE as + per [except.handle]/3. */ + +bool +handler_match_for_exception_type (tree handler, tree except_type) +{ + tree handler_type = HANDLER_TYPE (handler); + if (handler_type == NULL_TREE) + return true; /* ... */ + if (same_type_ignoring_top_level_qualifiers_p (handler_type, except_type)) + return true; + if (CLASS_TYPE_P (except_type) && CLASS_TYPE_P (handler_type)) + { + base_kind b_kind; + tree binfo = lookup_base (except_type, handler_type, ba_check, &b_kind, + tf_none); + if (binfo && binfo != error_mark_node) + return true; + } + if (TYPE_PTR_P (handler_type) || TYPE_PTRDATAMEM_P (handler_type)) + { + if (TREE_CODE (except_type) == NULLPTR_TYPE) + return true; + if ((TYPE_PTR_P (handler_type) && TYPE_PTR_P (except_type)) + || (TYPE_PTRDATAMEM_P (handler_type) + && TYPE_PTRDATAMEM_P (except_type))) + { + conversion *conv + = standard_conversion (handler_type, except_type, NULL_TREE, + /*c_cast_p=*/false, 0, tf_none); + if (conv && !conv->bad_p) + { + for (conversion *t = conv; t; t = next_conversion (t)) + switch (t->kind) + { + case ck_ptr: + case ck_fnptr: + case ck_qual: + case ck_identity: + break; + default: + return false; + } + return true; + } + } + } + return false; +} + /* A reference of the indicated TYPE is being bound directly to the expression represented by the implicit conversion sequence CONV. Return a conversion sequence for this binding. */ @@ -4876,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); @@ -6404,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); @@ -7435,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; @@ -7484,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: @@ -7585,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); @@ -8400,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 @@ -8428,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; } @@ -8642,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; @@ -8721,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, @@ -8746,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); @@ -9169,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); |