From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5FC86395447D; Tue, 10 Aug 2021 10:45:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FC86395447D From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101811] Error not helpful for misplaced 'template' Date: Tue, 10 Aug 2021 10:45:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Aug 2021 10:45:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101811 --- Comment #3 from Jonathan Wakely --- (In reply to Tobias Schl=C3=BCter from comment #2) > 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 w= hy > I would find clang's message more helpful and you didn't. >=20 > Here's clang's error message: > :6:9: error: out-of-line definition of 'f' does not match any > declaration in 'X' > void X::f() > ^ > :2:10: note: member declaration nearly matches > void f(); >=20 > When I read that I know 1) there are two 'f's. GCC tells you this too, there are two locations, one on line 2 and one on l= ine 6. > 2) the one on line 6 doesn't > match the one on line 2. That seems obvious from the fact there are two and GCC says "no declaration matches" :-) > 3) yet it ought to match (the) one in 'struct X'.=20 > So I as s user am left with wondering "how does it not match" which is > sufficient to resolve the problem. I honestly don't see how GCC's error doesn't provide exactly the same information. It could be clearer, but all the same information is there. > 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 fr= om > the set of "error" and "note"s. GCC's "error:" is a complete sentence too, it's just a lot more terse. > 2) "candidate" in gcc's error message appears to be a technical term or a It's the term used in the C++ standard for functions of the same name that = are participating in overload resolution. The compiler isn't actually doing overload resolution here so maybe it's a = poor choice of terminology that only makes sense from the compiler writers' perspective. > 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 wo= uld > go so far as to claim that it doesn't add any helpful information and thus > does more bad than good. I agree. I think this would be better than GCC's current diagnostic, and better than Clang's too: :6:6: error: no declaration matches 'template void X::f()' 6 | void X::f() | ^ :2:10: note: non-matching declaration 'void X::f()' is not a templa= te 2 | void f(); | ^ > Anyway, I'm well aware that the C++ frontend unfortunately doesn't get mu= ch > developer attention, That's not true at all. Over the past year it has more commits than all oth= er GCC front ends combined, and more distinct contributors than any other front end.=