/* Give a helpful diagnostic when implicit_conversion fails. */
static void
-implicit_conversion_error (location_t loc, tree type, tree expr)
+implicit_conversion_error (location_t loc, tree type, tree expr,
+ int flags)
{
tsubst_flags_t complain = tf_warning_or_error;
&& !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
+ else
{
- range_label_for_type_mismatch label (TREE_TYPE (expr), type);
- gcc_rich_location rich_loc (loc, &label,
- highlight_colors::percent_h);
- error_at (&rich_loc, "could not convert %qE from %qH to %qI",
- expr, TREE_TYPE (expr), type);
+ auto_diagnostic_group d;
+ 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);
+ gcc_rich_location rich_loc (loc, &label,
+ highlight_colors::percent_h);
+ error_at (&rich_loc, "could not convert %qE from %qH to %qI",
+ expr, TREE_TYPE (expr), type);
+ }
+ maybe_show_nonconverting_candidate (type, TREE_TYPE (expr), expr, flags);
}
}
else
{
if (complain & tf_error)
- implicit_conversion_error (loc, type, expr);
+ implicit_conversion_error (loc, type, expr, flags);
expr = error_mark_node;
}
if (!conv)
{
if (complain & tf_error)
- implicit_conversion_error (loc, type, expr);
+ implicit_conversion_error (loc, type, expr, flags);
expr = error_mark_node;
}
else if (processing_template_decl && conv->kind != ck_identity)
if (invalid_nonstatic_memfn_p (loc, expr, complain))
/* We displayed the error message. */;
else
- error_at (loc, "conversion from %qH to non-scalar type %qI requested",
- TREE_TYPE (expr), type);
+ {
+ auto_diagnostic_group d;
+ error_at (loc, "conversion from %qH to non-scalar type %qI requested",
+ TREE_TYPE (expr), type);
+ maybe_show_nonconverting_candidate (type, TREE_TYPE (expr), expr,
+ flags);
+ }
}
return error_mark_node;
}
};
static_assert(is_nothrow_convertible<int, B>::value, ""); // { dg-error "assert" }
// { dg-message "'int' is not nothrow convertible from 'B', because" "" { target *-*-* } .-1 }
+
+struct C {
+ explicit C(int); // { dg-message "not considered" }
+};
+static_assert(is_convertible<int, C>::value, ""); // { dg-error "assert" }
+// { dg-message "could not convert 'int' to 'C'" "" { target *-*-* } .-1 }
+
+struct D {
+ explicit operator int() const; // { dg-message "not considered" }
+};
+static_assert(is_convertible<D, int>::value, ""); // { dg-error "assert" }
+// { dg-message "could not convert 'D' to 'int'" "" { target *-*-* } .-1 }