aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-06-13 10:02:43 -0400
committerPatrick Palka <ppalka@redhat.com>2024-06-17 10:14:43 -0400
commit4df86402990e2f45e02a367f1734a22ebc041e98 (patch)
tree3fcb1374351ffefc5542e7e31b381f84492fc4a1
parent9583f781e17d4da881ee64db43af939402331413 (diff)
downloadgcc-4df86402990e2f45e02a367f1734a22ebc041e98.zip
gcc-4df86402990e2f45e02a367f1734a22ebc041e98.tar.gz
gcc-4df86402990e2f45e02a367f1734a22ebc041e98.tar.bz2
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 <jason@redhat.com> (cherry picked from commit 7fed7e9bbc57d502e141e079a6be2706bdbd4560)
-rw-r--r--gcc/cp/call.cc3
-rw-r--r--gcc/testsuite/g++.dg/overload/error7.C10
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 38b9c4f..f5584c9 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13488,7 +13488,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;
diff --git a/gcc/testsuite/g++.dg/overload/error7.C b/gcc/testsuite/g++.dg/overload/error7.C
new file mode 100644
index 0000000..de50ce5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/error7.C
@@ -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" }
+}