]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
diagnostics: suppress "note: " prefix in nested diagnostics [PR116253]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 11 Dec 2024 15:26:17 +0000 (10:26 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 11 Dec 2024 15:26:17 +0000 (10:26 -0500)
This patch is a followup to:
  "c++: use diagnostic nesting [PR116253]"

This patch tweaks how text output with experimental-nesting=yes
prints nested diagnostics, by omitting the leading "note: " from
nested notes.

This reduces the amount of visual cruft the user has to ignore when
reading C++ template errors; see the examples in the testsuite.

This doesn't affect the output for users who have not opted-in
to nested diagnostic-printing.

gcc/ChangeLog:
PR other/116253
* diagnostic-format-text.cc (build_prefix): Don't add the
"note: " prefix when showing nested diagnostics.

gcc/testsuite/ChangeLog:
PR other/116253
* g++.dg/concepts/nested-diagnostics-1-truncated.C: Update
expected output.
* g++.dg/concepts/nested-diagnostics-1.C: Likewise.
* g++.dg/concepts/nested-diagnostics-2.C: Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic-format-text.cc
gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C
gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C
gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c

index 2f26582fa2bebfc6de3ba71e1476986fa17187ee..856d25e8482cd0bff39bd8076e6e529e184362cc 100644 (file)
@@ -309,6 +309,12 @@ build_prefix (const diagnostic_info &diagnostic) const
   if (m_show_nesting && nesting_level > 0)
     {
       char *indent_prefix = build_indent_prefix (true);
+
+      /* Reduce verbosity of nested diagnostics by not printing "note: "
+        all the time.  */
+      if (diagnostic.kind == DK_NOTE)
+       return indent_prefix;
+
       char *result = build_message_string ("%s%s%s%s", indent_prefix,
                                           text_cs, text, text_ce);
       free (indent_prefix);
index 3f1f494dcf517c387a95579e901e1f39a8495ecd..0cb16105bb5ba38700fc6f828288698e679fb84c 100644 (file)
@@ -26,17 +26,17 @@ int main() {
 }
 
 /* { dg-begin-multiline-output "" }
-  * note: there are 3 candidates
-    * note: candidate 1: 'template<class auto:1>  requires  pettable<auto:1> void pet(auto:1)'
-      * note: template argument deduction/substitution failed:
-        * note: constraints not satisfied
+  * there are 3 candidates
+    * candidate 1: 'template<class auto:1>  requires  pettable<auto:1> void pet(auto:1)'
+      * template argument deduction/substitution failed:
+        * constraints not satisfied
           * In substitution of 'template<class auto:1>  requires  pettable<auto:1> void pet(auto:1) [with auto:1 = lizard]':
           * required from here
           * required for the satisfaction of 'pettable<auto:1>' [with auto:1 = lizard]
-          * note: no operand of the disjunction is satisfied
-          * note: set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
-    * note: candidate 2: 'void pet(dog)'
-      * note: no known conversion for argument 1 from 'lizard' to 'dog'
-    * note: candidate 3: 'void pet(cat)'
-      * note: no known conversion for argument 1 from 'lizard' to 'cat'
+          * no operand of the disjunction is satisfied
+          * set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
+    * candidate 2: 'void pet(dog)'
+      * no known conversion for argument 1 from 'lizard' to 'dog'
+    * candidate 3: 'void pet(cat)'
+      * no known conversion for argument 1 from 'lizard' to 'cat'
    { dg-end-multiline-output "" } */
index 8713046df6d7277e3f4d230bdd96f765e802805f..e642676841d3e3899260c1d0eecbb0b9472fe3fb 100644 (file)
@@ -27,26 +27,26 @@ int main() {
 }
 
 /* { dg-begin-multiline-output "" }
-  * note: there are 3 candidates
-    * note: candidate 1: 'template<class auto:1>  requires  pettable<auto:1> void pet(auto:1)'
-      * note: template argument deduction/substitution failed:
-        * note: constraints not satisfied
+  * there are 3 candidates
+    * candidate 1: 'template<class auto:1>  requires  pettable<auto:1> void pet(auto:1)'
+      * template argument deduction/substitution failed:
+        * constraints not satisfied
           * In substitution of 'template<class auto:1>  requires  pettable<auto:1> void pet(auto:1) [with auto:1 = lizard]':
           * required from here
           * required for the satisfaction of 'pettable<auto:1>' [with auto:1 = lizard]
-          * note: no operand of the disjunction is satisfied
-            * note: the operand 'has_member_pet<T>' is unsatisfied because
+          * no operand of the disjunction is satisfied
+            * the operand 'has_member_pet<T>' is unsatisfied because
               * required for the satisfaction of 'has_member_pet<T>' [with T = lizard]
               * required for the satisfaction of 'pettable<auto:1>' [with auto:1 = lizard]
               * in requirements with 'T t' [with T = lizard]
-              * note: the required expression 't.pet()' is invalid, because
+              * the required expression 't.pet()' is invalid, because
                 * error: 'struct lizard' has no member named 'pet'
-            * note: the operand 'has_default_pet<T>' is unsatisfied because
+            * the operand 'has_default_pet<T>' is unsatisfied because
               * required for the satisfaction of 'has_default_pet<T>' [with T = lizard]
               * required for the satisfaction of 'pettable<auto:1>' [with auto:1 = lizard]
               * error: 'is_pettable' is not a member of 'lizard'
-    * note: candidate 2: 'void pet(dog)'
-      * note: no known conversion for argument 1 from 'lizard' to 'dog'
-    * note: candidate 3: 'void pet(cat)'
-      * note: no known conversion for argument 1 from 'lizard' to 'cat'
+    * candidate 2: 'void pet(dog)'
+      * no known conversion for argument 1 from 'lizard' to 'dog'
+    * candidate 3: 'void pet(cat)'
+      * no known conversion for argument 1 from 'lizard' to 'cat'
    { dg-end-multiline-output "" } */
index 4205dbe8c75dfa4240b2ddce8daff4df43c8d87a..cc15f11d63f41d6c27112c8729575747084bcc65 100644 (file)
@@ -21,18 +21,18 @@ int main() {
 }
 
 /* { dg-begin-multiline-output "" }
-  * note: there are 3 candidates
-    * note: candidate 1: 'template<class T>  requires  pettable<T> void pet(T)'
-      * note: template argument deduction/substitution failed:
-        * note: constraints not satisfied
+  * there are 3 candidates
+    * candidate 1: 'template<class T>  requires  pettable<T> void pet(T)'
+      * template argument deduction/substitution failed:
+        * constraints not satisfied
           * In substitution of 'template<class T>  requires  pettable<T> void pet(T) [with T = donkey]':
           * required from here
           * required for the satisfaction of 'pettable<T>' [with T = donkey]
           * in requirements with 'T t' [with T = donkey]
-          * note: the required expression 't.pet()' is invalid
-          * note: set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
-    * note: candidate 2: 'void pet(dog)'
-      * note: no known conversion for argument 1 from 'donkey' to 'dog'
-    * note: candidate 3: 'void pet(cat)'
-      * note: no known conversion for argument 1 from 'donkey' to 'cat'
+          * the required expression 't.pet()' is invalid
+          * set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
+    * candidate 2: 'void pet(dog)'
+      * no known conversion for argument 1 from 'donkey' to 'dog'
+    * candidate 3: 'void pet(cat)'
+      * no known conversion for argument 1 from 'donkey' to 'cat'
    { dg-end-multiline-output "" } */
index 91b1056d9557f3ead7418a97628b93cb55be3ba6..f44c8eb458d27cbd4be10208164d258495c673b9 100644 (file)
@@ -9,16 +9,16 @@ void test_nesting (void)
 }
 
 /* { dg-begin-multiline-output "" }
-  * (level 1):note: child 0
-    * (level 2):note: grandchild 0 0
-    * (level 2):note: grandchild 0 1
-    * (level 2):note: grandchild 0 2
-  * (level 1):note: child 1
-    * (level 2):note: grandchild 1 0
-    * (level 2):note: grandchild 1 1
-    * (level 2):note: grandchild 1 2
-  * (level 1):note: child 2
-    * (level 2):note: grandchild 2 0
-    * (level 2):note: grandchild 2 1
-    * (level 2):note: grandchild 2 2
+  * (level 1):child 0
+    * (level 2):grandchild 0 0
+    * (level 2):grandchild 0 1
+    * (level 2):grandchild 0 2
+  * (level 1):child 1
+    * (level 2):grandchild 1 0
+    * (level 2):grandchild 1 1
+    * (level 2):grandchild 1 2
+  * (level 1):child 2
+    * (level 2):grandchild 2 0
+    * (level 2):grandchild 2 1
+    * (level 2):grandchild 2 2
    { dg-end-multiline-output "" } */
index e843d196aaf12e6a5e40a34fa8a63b68969021c3..39e29f7a71a844470307c06bf5bd7d858763d07d 100644 (file)
@@ -9,16 +9,16 @@ void test_nesting (void)
 }
 
 /* { dg-begin-multiline-output "" }
-  • note: child 0
-    • note: grandchild 0 0
-    • note: grandchild 0 1
-    • note: grandchild 0 2
-  • note: child 1
-    • note: grandchild 1 0
-    • note: grandchild 1 1
-    • note: grandchild 1 2
-  • note: child 2
-    • note: grandchild 2 0
-    • note: grandchild 2 1
-    • note: grandchild 2 2
+  • child 0
+    • grandchild 0 0
+    • grandchild 0 1
+    • grandchild 0 2
+  • child 1
+    • grandchild 1 0
+    • grandchild 1 1
+    • grandchild 1 2
+  • child 2
+    • grandchild 2 0
+    • grandchild 2 1
+    • grandchild 2 2
    { dg-end-multiline-output "" } */
index 687acf98fecef76f9c2a3618062bed5df27dcb75..e10342950a2613f6a54e7b9de8479d2cd4517657 100644 (file)
@@ -9,16 +9,16 @@ void test_nesting (void)
 }
 
 /* { dg-begin-multiline-output "" }
-  * note: child 0
-    * note: grandchild 0 0
-    * note: grandchild 0 1
-    * note: grandchild 0 2
-  * note: child 1
-    * note: grandchild 1 0
-    * note: grandchild 1 1
-    * note: grandchild 1 2
-  * note: child 2
-    * note: grandchild 2 0
-    * note: grandchild 2 1
-    * note: grandchild 2 2
+  * child 0
+    * grandchild 0 0
+    * grandchild 0 1
+    * grandchild 0 2
+  * child 1
+    * grandchild 1 0
+    * grandchild 1 1
+    * grandchild 1 2
+  * child 2
+    * grandchild 2 0
+    * grandchild 2 1
+    * grandchild 2 2
    { dg-end-multiline-output "" } */