]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Improve diagnostic for implicit conversion errors [PR115163]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 10 Jan 2026 23:02:45 +0000 (10:02 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Mon, 12 Jan 2026 09:12:29 +0000 (20:12 +1100)
commit3e8ce187dc4595da3d2f41a0fb09ee9cd2e437ff
tree5bd4cec47374f82be2c8f366cafa55a7a21384da
parentdd8df074c9ceaa723e82f06bef8714f46ecccb18
c++: Improve diagnostic for implicit conversion errors [PR115163]

This patch adds a note to indicate if any viable explicit conversion
functions were skipped if an implicit conversion failed to occur.

Perhaps the base diagnostic in ocp_convert can be further improved for
class types as well, as the current message is not very clear, but I've
not looked into that for this patch.

PR c++/115163

gcc/cp/ChangeLog:

* call.cc (implicit_conversion_error): Add flags argument, call
maybe_show_nonconverting_candidate.
(build_converted_constant_expr_internal): Pass flags to
implicit_conversion_error.
(perform_implicit_conversion_flags): Likewise.
* cvt.cc (ocp_convert): Call maybe_show_nonconverting_candidate
on conversion error.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_convertible7.C: Add new testcases.
* g++.dg/diagnostic/explicit2.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/call.cc
gcc/cp/cvt.cc
gcc/testsuite/g++.dg/diagnostic/explicit2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/is_convertible7.C