diagnostics: suppress "note: " prefix in nested diagnostics [PR116253]

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>
This commit is contained in:
David Malcolm 2024-12-11 10:26:17 -05:00
parent d3dd24acd7
commit 7435d1dbae
7 changed files with 74 additions and 68 deletions

View 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);

View 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 "" } */

View 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 "" } */

View 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 "" } */

View 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 "" } */

View 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 "" } */

View 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 "" } */