[Bug c++/101811] Error not helpful for misplaced 'template'

tobi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Aug 10 04:57:53 GMT 2021


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

--- Comment #2 from Tobias Schlüter <tobi at gcc dot gnu.org> ---
Hi Jonathan,
actually I found clang's error message a lot more helpful, I just didn't bother
to write it explicitly, especially given that my compiler explorer link shows
it for everybody else to make the same observation.  Well, you came to a
different conclusion comparing the two and so I was wondering why I would find
clang's message more helpful and you didn't.

Here's clang's error message:
<source>:6:9: error: out-of-line definition of 'f' does not match any
declaration in 'X'
void X::f()
        ^
<source>:2:10: note: member declaration nearly matches
    void f();

When I read that I know 1) there are two 'f's.  2) the one on line 6 doesn't
match the one on line 2.  3) yet it ought to match (the) one in 'struct X'.  So
I as s user am left with wondering "how does it not match" which is sufficient
to resolve the problem.

Let me point to three things where gcc ends up making things harder to
understand in my opinion:
1) clang uses (almost) complete sentences.  One doesn't have to figure out how
the parts of the error message relate to then form a logical whole from the set
of "error" and "note"s.
2) "candidate" in gcc's error message appears to be a technical term or a
gcc-specific term, one has to make sense of what it means from the context
("nothing matches -> oh, so this was a candidate for a match and this is what
'candidate' means here" whereas clang's error implies directly that the 'f' on
line 2 was really close to the one on line 6.
3) gcc's second note, which points to the struct declaration isn't really
helpful, it just floats in the ether for the user to make sense of.  I would go
so far as to claim that it doesn't add any helpful information and thus does
more bad than good.

Anyway, I'm well aware that the C++ frontend unfortunately doesn't get much
developer attention, so I'm not writing these PRs to complain, but to give a
potential future FE developer a good starting point to get their hands dirty :)


More information about the Gcc-bugs mailing list