c++: add color to function decl printing
commit69dd5ca3484ee514c1323dfbcf4ef4358cea57bb
authorJason Merrill <jason@redhat.com>
Fri, 18 Jun 2021 09:45:02 +0000 (18 05:45 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 6 May 2022 20:34:51 +0000 (6 16:34 -0400)
tree977459ac84579eac53c159e7d22f2e957bcf793a
parente4e053a63b153039a7905901806a4f4a3154988b
c++: add color to function decl printing

In reading C++ diagnostics, it's often hard to find the name of the function
in the middle of the template header, return type, parameters, and template
arguments.  So let's colorize it, and maybe the template argument bindings
while we're at it.

I've somewhat arbitrarily chosen bold green for the function name, and
non-bold magenta for the template arguments.

A side-effect of this is that when this happens in a quote (i.e. %qD), the
rest of the quote after the function name is no longer bold.  I think that's
acceptable; returning to the bold would require maintaining a colorize stack
instead of the on/off controls we have now.

gcc/cp/ChangeLog:

* error.cc (decl_to_string): Add show_color parameter.
(subst_to_string): Likewise.
(cp_printer): Pass it.
(type_to_string): Set pp_show_color.
(dump_function_name): Use "fnname" color.
(dump_template_bindings): Use "targs" color.
(struct colorize_guard): New.
(reinit_cxx_pp): Clear pp_show_color.

gcc/ChangeLog:

* diagnostic-color.cc: Add fnname and targs color entries.
* doc/invoke.texi: Document them.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/function-color1.C: New test.
gcc/cp/error.cc
gcc/diagnostic-color.cc
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/diagnostic/function-color1.C [new file with mode: 0644]