[Bug c++/15787] New: Poor error message
igodard at pacbell dot net
gcc-bugzilla@gcc.gnu.org
Wed Jun 2 21:31:00 GMT 2004
The actual problem in the test case is a missing "}", which fact appears nowhere in the message. The message talks about a "primary-expression", which is technically correct but reflects a compiler- and formal syntax-centric view. A user will in general neither know nor care what a primary-expression is; he wants to know what's wrong in terms of his code. The education, experience and knowledge of compiler users is *not* the same as of compiler writers :-)
The great bulk of syntactic arrors are bracket errors or missing semis. Now that you have a recursive descent parser, it is trivial to have the compiler suggest a plausible fix for these. For example, have the compiler keep a side stack of brackets entered and not exited. If you get a closer that matches the *second* item on the stack then your message offers the closers of the *top* item on the stack as suggestions.
In the case of this code, the top item is "{" and the second is "if". When the parse error happens the cursor is on "else", which matches the "if". So you produce a message "expected primary-expression before 'else'; possibly a missing '}'?". This same stack can be used for repair.
Ivan
--
Summary: Poor error message
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: igodard at pacbell dot net
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15787
More information about the Gcc-bugs
mailing list