]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: improve nesting in print_z_candidate [PR121966]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 17 Sep 2025 20:39:32 +0000 (16:39 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 17 Sep 2025 20:39:32 +0000 (16:39 -0400)
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 <dmalcolm@redhat.com>
gcc/cp/call.cc

index d11961a48ada48672c978c74a8d711a302d812f2..550ce5f712be289b594d15716ee90b070e3db19a 100644 (file)
@@ -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 "