public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101844] New: Don't pretty print template parameter names that aren't needed
@ 2021-08-10 11:12 redi at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: redi at gcc dot gnu.org @ 2021-08-10 11:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101844

            Bug ID: 101844
           Summary: Don't pretty print template parameter names that
                    aren't needed
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

The diagnostic for this invalid code has ugly pretty printing:

struct A
{
  template<int> void f();
};

void A::f() { }


t.C:6:6: error: no declaration matches ‘void A::f()’
    6 | void A::f() { }
      |      ^
t.C:3:22: note: candidate is: ‘template<int <anonymous> > void A::f()’
    3 |   template<int> void f();
      |                      ^

There is no reason to print "<anonymous>" in the note here. Nothing else in the
declarator needs to refer to it (it can't refer to it, since it hasn't got a
name!) so printing it just makes the diagnostic harder to read.

Printing <anonymous> is strictly worse than printing nothing at all, but I
think we shouldn't print any template parameter names if they aren't used later
in the declarator. For example:

struct A
{
  template<int ReallyLongAndVerboseAndAlsoUglyName> void f();
};

void A::f() { }


This prints:

t.C:6:6: error: no declaration matches ‘void A::f()’
    6 | void A::f() { }
      |      ^
t.C:3:58: note: candidate is: ‘template<int
ReallyLongAndVerboseAndAlsoUglyName> void A::f()’
    3 |   template<int ReallyLongAndVerboseAndAlsoUglyName> void f();
      |                                                          ^

I don't see any benefit to printing the name in the note, it just adds noise.

Obviously there are some cases where we need to pretty print the template
parameter name, because it's used in another parameter:

  template<bool A, std::enable_if_t<A, bool> = true> void f();

Here we need to print A so that "enable_if<A, bool>" can use it:

t.C:5:59: note: candidate is: ‘template<bool A, typename std::enable_if<A,
bool>::type <anonymous> > void A::f()’

However, we don't need the <anonymous> for the second parameter.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-10 11:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 11:12 [Bug c++/101844] New: Don't pretty print template parameter names that aren't needed redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).