c++: ICE with bad conversion shortcutting [PR104622]
authorPatrick Palka <ppalka@redhat.com>
Sat, 12 Mar 2022 20:00:49 +0000 (15:00 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sat, 12 Mar 2022 20:00:49 +0000 (15:00 -0500)
commit03c83cf7aa1110e427beb00ea95767dfaf50d694
treebda379f6a95aee2a948ea1e4d61f05971829c201
parent9413bb55185b9e88d84e91d5145d59f9f83b884a
c++: ICE with bad conversion shortcutting [PR104622]

When shortcutting bad argument conversions during overload resolution,
we assume conversions get computed in sequential order and that therefore
the conversion array is incomplete iff the last conversion is missing.
But this assumption turns out to be wrong for templates, because during
deduction check_non_deducible_conversion can compute an argument
conversion out of order.

So in the testcase below, at the end of add_template_candidate the
conversion array looks like {bad_conv, NULL, good_conv} where the last
conversion was computed during deduction and the first one later from
add_function_candidate.  We need to add this candidate to bad_fns since
not all of its argument conversions were computed, but we don't do so
because the last conversion isn't missing.

This patch fixes this by checking for a missing conversion exhaustively
instead.  In passing, this cleans up check_non_deducible_conversion given
that the only values of 'strict' we expect to see here the enumerators
of unification_kind_t.

PR c++/104622

gcc/cp/ChangeLog:

* call.cc (missing_conversion_p): Define.
(add_candidates): Use it.
* pt.cc (check_non_deducible_conversion): Change type of strict
parameter to unification_kind_t and directly test for DEDUCE_CALL.

gcc/testsuite/ChangeLog:

* g++.dg/template/conv18.C: New test.
gcc/cp/call.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/conv18.C [new file with mode: 0644]