https://gcc.gnu.org/g:41f071a64ff7027a98e6b6a7e3641156e3be70e0

commit r16-3941-g41f071a64ff7027a98e6b6a7e3641156e3be70e0
Author: David Malcolm <[email protected]>
Date:   Wed Sep 17 16:39:32 2025 -0400

    c++: improve nesting in print_z_candidate [PR121966]
    
    Comment #2 of PR c++/121966 notes that the "inherited here" messages
    should be nested *within* the note they describe.
    
    Implemented by this patch, which also nests other notes emitted for
    rejection_reason within the first note of print_z_candidate.
    
    gcc/cp/ChangeLog:
            PR c++/121966
            * call.cc (print_z_candidate): Consolidate instances of
            auto_diagnostic_nesting_level into one, above the "inherited here"
            message so that any such message is nested within the note,
            and any messages emitted due to the switch on rejection_reason are
            similarly nested within the note.
    
    Signed-off-by: David Malcolm <[email protected]>

Diff:
---
 gcc/cp/call.cc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index d11961a48ada..550ce5f712be 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4104,15 +4104,18 @@ print_z_candidate (location_t loc, const char *msgstr,
     inform (cloc, "%s%#qD (rewritten)", msg, fn);
   else
     inform (cloc, "%s%#qD", msg, fn);
+
+  auto_diagnostic_nesting_level sentinel;
+
   if (fn != candidate->fn)
     {
       cloc = location_of (candidate->fn);
       inform (cloc, "inherited here");
     }
+
   /* Give the user some information about why this candidate failed.  */
   if (candidate->reason != NULL)
     {
-      auto_diagnostic_nesting_level sentinel;
       struct rejection_reason *r = candidate->reason;
 
       switch (r->code)
@@ -4172,10 +4175,7 @@ print_z_candidate (location_t loc, const char *msgstr,
                  "class type is invalid");
          break;
        case rr_constraint_failure:
-         {
-           auto_diagnostic_nesting_level sentinel;
-           diagnose_constraints (cloc, fn, NULL_TREE);
-         }
+         diagnose_constraints (cloc, fn, NULL_TREE);
          break;
        case rr_inherited_ctor:
          inform (cloc, "an inherited constructor is not a candidate for "

Reply via email to