Skip to content

Commit 4df8640

Browse files
author
Patrick Palka
committed
c++: ICE w/ ambig and non-strictly-viable cands [PR115239]
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 <[email protected]> (cherry picked from commit 7fed7e9)
1 parent 9583f78 commit 4df8640

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

gcc/cp/call.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13488,7 +13488,8 @@ tourney (struct z_candidate *candidates, tsubst_flags_t complain)
1348813488
{
1348913489
previous_worse_champ = nullptr;
1349013490
champ = &(*challenger)->next;
13491-
if (!*champ || !(*champ)->viable)
13491+
if (!*champ || !(*champ)->viable
13492+
|| (*champ)->viable < (*challenger)->viable)
1349213493
{
1349313494
champ = nullptr;
1349413495
break;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// PR c++/115239
2+
3+
bool foo(char *, long); // #1, strictly viable, ambig with #2
4+
bool foo(char *, unsigned); // #2, strictly viable, ambig with #1
5+
bool foo(char, long); // #3, non-strictly viable
6+
bool foo(char, unsigned); // #4, non-strictly viable
7+
8+
int main() {
9+
foo((char *)0, 0); // { dg-error "ambiguous" }
10+
}

0 commit comments

Comments
 (0)