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.