This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ and useful error messages
- To: pfeifer at dbai dot tuwien dot ac dot at (Gerald Pfeifer)
- Subject: Re: C++ and useful error messages
- From: Joe Buck <jbuck at racerx dot synopsys dot com>
- Date: Wed, 20 Dec 2000 12:58:36 -0800 (PST)
- Cc: gcc at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
>
> 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