[pushed:,r16-3940] c++: fix count of z candidates for non-viable candidates [PR121966]

Message ID 20250917204735.2386432-1-dmalcolm@redhat.com
State Committed
Commit c0b21d1f45ac6a249974982c1a7f7515efb78747
Headers
Series [pushed:,r16-3940] c++: fix count of z candidates for non-viable candidates [PR121966] |

Commit Message

David Malcolm Sept. 17, 2025, 8:47 p.m. UTC
  In r15-6116-gd3dd24acd74605 I updated print_z_candidates to show the
number of candidates, and a number for each candidate.

PR c++/121966 notes that the printed count is sometimes higher than
what's actually printed: I missed the case where candidates in the
list aren't printed due to not being viable.

Fixed thusly.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r16-3940-gc0b21d1f45ac6a.

gcc/cp/ChangeLog:
	PR c++/121966
	* call.cc (print_z_candidates): Copy the filtering logic on viable
	candidates from the printing loop to the counting loop, so that
	num_candidates matches the number of iterations of the latter
	loop.
---
 gcc/cp/call.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 02cef63a4538..d11961a48ada 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4255,7 +4255,11 @@  print_z_candidates (location_t loc, struct z_candidate *candidates,
 
   int num_candidates = 0;
   for (auto iter = candidates; iter; iter = iter->next)
-    ++num_candidates;
+    {
+      if (only_viable_p.is_true () && iter->viable != 1)
+	break;
+      ++num_candidates;
+    }
 
   inform_n (loc,
 	    num_candidates, "there is %i candidate", "there are %i candidates",