Skip to content

Commit

Permalink
c++: ICE w/ ambig and non-strictly-viable cands [PR115239]
Browse files Browse the repository at this point in the history
Here during overload resolution we have two strictly viable ambiguous
candidates #1 and #2, and two non-strictly viable candidates #3 and #4
which we hold on to ever since r14-6522.  These latter candidates have
an empty second arg conversion since the first arg conversion was deemed
bad, and this trips up joust when called on #3 and #4 which assumes all
arg conversions are there.

We can fix this by making joust robust to empty arg conversions, but in
this situation we shouldn't need to compare #3 and #4 at all given that
we have a strictly viable candidate.  To that end, this patch makes
tourney shortcut considering non-strictly viable candidates upon
encountering ambiguity between two strictly viable candidates (taking
advantage of the fact that the candidates list is sorted according to
viability via splice_viable).

	PR c++/115239

gcc/cp/ChangeLog:

	* call.cc (tourney): Don't consider a non-strictly viable
	candidate as the champ if there was ambiguity between two
	strictly viable candidates.

gcc/testsuite/ChangeLog:

	* g++.dg/overload/error7.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
  • Loading branch information
Patrick Palka committed Jun 13, 2024
1 parent 3f3eb16 commit 7fed7e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gcc/cp/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13490,7 +13490,8 @@ tourney (struct z_candidate *candidates, tsubst_flags_t complain)
{
previous_worse_champ = nullptr;
champ = &(*challenger)->next;
if (!*champ || !(*champ)->viable)
if (!*champ || !(*champ)->viable
|| (*champ)->viable < (*challenger)->viable)
{
champ = nullptr;
break;
Expand Down
10 changes: 10 additions & 0 deletions gcc/testsuite/g++.dg/overload/error7.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// PR c++/115239

bool foo(char *, long); // #1, strictly viable, ambig with #2
bool foo(char *, unsigned); // #2, strictly viable, ambig with #1
bool foo(char, long); // #3, non-strictly viable
bool foo(char, unsigned); // #4, non-strictly viable

int main() {
foo((char *)0, 0); // { dg-error "ambiguous" }
}

0 comments on commit 7fed7e9

Please sign in to comment.