This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix a C++ parser error message (PR c++/9851)


Mark Mitchell <mark@codesourcery.com> writes:

> >PR c++/9851 is about a bad error message generated by the C++ parser.
> >
> >For this invalid test case:
> >
> >struct goo {
> >  void do_nothing () {};
> >};
> >
> >struct foo {
> >  foo () { g_.do_nothing (); }
> >  goo * g_;
> >};
> >
> >the current parser generates this:
> >
> >foo.cc: In constructor `foo::foo()':
> >foo.cc:6: error: `do_nothing' has not been declared
> >foo.cc:6: error: expected `::' before '(' token
> >foo.cc:6: error: expected `~' before '(' token
> >foo.cc:6: error: expected identifier before '(' token
> >
> >This is a pretty bad set of error messages for an easy mistake.
> >
> Indeed.
> 
> I think that you could probably just insert a check after this code in
> cp_parser_pseudo_destructor_name:
> 
>       /* Look for the type-name.  */
>       *scope = TREE_TYPE (cp_parser_type_name (parser));
> 
> If *scope is not an aggregate type, issue an error message with
> cp_parser_error and return error_mark_node.  That seems simpler than
> your patch.

That's arguably a little bit too late, though, since we will have
already issued this error:
    foo.cc:6: error: `do_nothing' has not been declared
That error is issued by the call to cp_parser_type_name().

I don't yet see a good way to avoid the error message without doing a
tentative parse.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]