[PATCH v2 RFC] c++: add color to function decl printing

Jason Merrill jason@redhat.com
Mon Dec 13 14:58:11 GMT 2021


On 12/13/21 06:02, Jonathan Wakely wrote:
> On Sun, 12 Dec 2021 at 05:39, Jason Merrill <jason@redhat.com 
> <mailto:jason@redhat.com>> wrote:
>  >
>  > 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.  I'm not at all attached to
>  > these choices.
>  >
>  > A side-effect 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.
>  >
>  > Any thoughts?
> 
> I thought I was going to love this ... and it's a nice little 
> improvement, but I didn't love it as much as I expected.
> 
> Is it intentional that only the last function in the instantiation stack 
> gets colourized? In this example the function on line 390 isn't highlighted:
> 
> /home/jwakely/gcc/12/include/c++/12.0.0/bits/ranges_base.h:390:12:  required 
> by substitution of 'template<class _Tp>  requires 
> (is_bounded_array_v<typename std::remove_reference<_Tp>::type>) || 
> (__member_size*<_Tp>) || (__adl_size<_Tp>) || (__sentinel_size<_Tp>) 
> constexpr auto std::ranges::__cust_access::_Size::operator()(_Tp&&) 
> const [with _Tp = adl::Footie (&)[]]*'

Oops, I needed to change subst_to_string as well.  Updated patch below.

> Aside: it's a little odd that the first caret diagnostic there only 
> highlights the word "operator" and not the name of the function, 
> "operator()".

Yes, I imagine we need to adjust DECL_SOURCE_LOCATION to use a range 
instead of assuming the location of the first token is sufficient.

Jason
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-c-add-color-to-function-decl-printing.patch
Type: text/x-patch
Size: 10016 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211213/000a82a3/attachment.bin>


More information about the Gcc-patches mailing list