This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ 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


> 
> 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

This should be fixable with minor work on the grammar.  I looked into
what the parser does with just

class C {
	vector<int> vi;
};

which produces the same error (you also get it when you mis-spell the
name of a template).

We reduce IDENTIFIER '<' template_arg_list_opt template_close_bracket
to notype_template_declarator.  This is then reduced, in turn, to
direct_notype_declarator, and then to notype_declarator, and then to
fn.def2.  At this point, error is declared.  But it seems that we
should already have enough information to give a better error message.

Note that if the use of vector without std:: comes in a different
position, we get a more reasonable answer.  For

int foo() {
        vector<int> vi;
}

we get

emsg2.C: In function `int foo()':
emsg2.C:2: `vector' undeclared (first use this function)
emsg2.C:2: (Each undeclared identifier is reported only once for each function 
   it appears in.)
emsg2.C:2: parse error before `>' token

That sort of message should point people in the right direction, in any
case; if more is desired, when an undeclared identifier is found, the
compiler could look for std::identifier and, if found in std, generate
something like

emsg2.C: In function `int foo()':
emsg2.C:2: `vector' undeclared (first use this function)
emsg2.C:2: (Each undeclared identifier is reported only once for each function 
   it appears in.)
emsg2.C:2: Perhaps you meant to use `std::vector' ?
emsg2.C:2: parse error before `>' token


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