This is the mail archive of the gcc@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]

Re: C++ and useful error messages


Gerald wrote:

> I predict that after the release of GCC 3.0 we will see an avalanche of
> bug reports/complaints that g++ fails for the most simple kind of input:
> 
>   #include <vector>
>   class C {
>     vector<int> vi;
>     };

>   % gccvs x.cc
>   x.cc:3: syntax error before `;' token

I've been investigating this, and it's really a more pervasive problem,
but it also seems that we can get some substantial improvement without
excessive effort.

to see more problems. try one-line files like

ostream some_stream;

or

vector<int> foo;

or

vector<int> foo(10);

In all these cases the error recovery is awful, and we get a message
complaining about the ';' or the '(' (the parsing is the same for
file-scope objects or members of classes).

Now, I'm in over my head in messing with cp/parse.y, but I've done a lot
of yacc/bison in my time, and it seems, from looking at the parse tables,
that we might be able to add some new rules for datadef without
introducing new ambuities:

	IDENTIFIER IDENTIFIER opt_exprlist ';'

where opt_exprlist is either nothing or 
'(' nonnull_exprlist ')'
.

This is almost certainly an attempt to declare $2 as an object of type $1,
and in fact, HP's aCC says in cases like this, for "foo bar(3);"

'foo' is used as a type, but has not been defined as a type.

HP also appears to generate a declaration of bar, in that bar is not
later complained about as an undefined identifier.  This reduces the
cascade of errors.

Next, for templates

	IDENTIFIER '<' template_arg_list_opt template_close_bracket
		 IDENTIFIER opt_exprlist ';'

Here we can report that the first identifier is being used as a template,
but has not been defined as a template, and the second identifier can
get a dummy declaration.

Finally, as I suggested before, for any undeclared identifier, we can
look in std:: and report an additional "perhaps you meant" message if
found there.


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