public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4807] c++: fix tourney logic
@ 2023-10-20 20:30 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-10-20 20:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ff04531b66102110e1c7fbd3a34d8e42ba7152a8

commit r14-4807-gff04531b66102110e1c7fbd3a34d8e42ba7152a8
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Oct 5 10:45:00 2023 -0400

    c++: fix tourney logic
    
    In r13-3766 I changed the logic at the end of tourney to avoid redundant
    comparisons, but the change also meant skipping any less-good matches
    between the champ_compared_to_predecessor candidate and champ itself.
    
    This should not be a correctness issue, since we believe that joust is a
    partial order.  But it can lead to missed warnings, as in this testcase.
    
    gcc/cp/ChangeLog:
    
            * call.cc (tourney): Only skip champ_compared_to_predecessor.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/warn/Wsign-promo1.C: New test.

Diff:
---
 gcc/cp/call.cc                           |  5 +++--
 gcc/testsuite/g++.dg/warn/Wsign-promo1.C | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 657eca93d23a..a49fde949d5d 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13227,10 +13227,11 @@ tourney (struct z_candidate *candidates, tsubst_flags_t complain)
      been compared to.  */
 
   for (challenger = candidates;
-       challenger != champ
-	 && challenger != champ_compared_to_predecessor;
+       challenger != champ;
        challenger = challenger->next)
     {
+      if (challenger == champ_compared_to_predecessor)
+	continue;
       fate = joust (champ, challenger, 0, complain);
       if (fate != 1)
 	return NULL;
diff --git a/gcc/testsuite/g++.dg/warn/Wsign-promo1.C b/gcc/testsuite/g++.dg/warn/Wsign-promo1.C
new file mode 100644
index 000000000000..51b76eee735f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wsign-promo1.C
@@ -0,0 +1,15 @@
+// Check that we get joust warnings from comparing the final champ to a
+// candidate between it and the previous champ.
+
+// { dg-additional-options -Wsign-promo }
+
+struct A { A(int); };
+
+enum E { e };
+
+int f(int, A);
+int f(unsigned, A);
+int f(int, int);
+
+int i = f(e, 42);		// { dg-warning "passing 'E'" }
+// { dg-warning "in call to 'int f" "" { target *-*-* } .-1 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-20 20:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-20 20:30 [gcc r14-4807] c++: fix tourney logic Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).