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. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. OK for trunk? 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 <dmalc...@redhat.com> --- gcc/diagnostic-format-text.cc | 6 +++++ .../concepts/nested-diagnostics-1-truncated.C | 20 ++++++++-------- .../g++.dg/concepts/nested-diagnostics-1.C | 24 +++++++++---------- .../g++.dg/concepts/nested-diagnostics-2.C | 20 ++++++++-------- ...c-test-nesting-text-indented-show-levels.c | 24 +++++++++---------- ...ostic-test-nesting-text-indented-unicode.c | 24 +++++++++---------- .../diagnostic-test-nesting-text-indented.c | 24 +++++++++---------- 7 files changed, 74 insertions(+), 68 deletions(-) diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostic-format-text.cc index 217733784e8d..a74039138cf4 100644 --- a/gcc/diagnostic-format-text.cc +++ b/gcc/diagnostic-format-text.cc @@ -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); diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C index 58c5652058e5..2874580c3863 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C @@ -26,17 +26,17 @@ int main() { } /* { dg-begin-multiline-output "" } - * note: we found 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 + * we found 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 "" } */ diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C index 69f7179172ee..19cc324326b9 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C @@ -27,26 +27,26 @@ int main() { } /* { dg-begin-multiline-output "" } - * note: we found 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 + * we found 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 "" } */ diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C index 5ce7c68dcccb..bdf4cd481da5 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C @@ -21,18 +21,18 @@ int main() { } /* { dg-begin-multiline-output "" } - * note: we found 3 candidates - * note: candidate 1: 'template<class T> requires pettable<T> void pet(T)' - * note: template argument deduction/substitution failed: - * note: constraints not satisfied + * we found 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 "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c index 91b1056d9557..f44c8eb458d2 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c @@ -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 "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c index e843d196aaf1..39e29f7a71a8 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c @@ -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 "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c index 687acf98fece..e10342950a26 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c @@ -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 "" } */ -- 2.26.3