This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Improved parser diagnosis
- To: <gcc-patches at gcc dot gnu dot org>
- Subject: C++ PATCH: Improved parser diagnosis
- From: Gerald Pfeifer <pfeifer at dbai dot tuwien dot ac dot at>
- Date: Tue, 20 Mar 2001 09:12:52 +0100 (CET)
- cc: Joe Buck <jbuck at synopsys dot COM>
This patch is important for GCC 3.0.
A while ago I complained about our parser providing inadequate error
messages, especially when refering to types from namespace std without
explicitly importing or qualifying that namespace.
Joe had a close look and provided an excellent analysis (and guidance),
on which the following patch is based.
For the snippet
intint i;
intint j(1);
vector<int> v;
vector<short> w(1);
we now complain
x.cc:1: 'intint' is used as a type, but is not defined as a type.
x.cc:2: 'intint' is used as a type, but is not defined as a type.
x.cc:3: 'vector' is used as a type, but is not defined as a type.
x.cc:4: 'vector' is used as a type, but is not defined as a type.
instead of
x.cc:1: syntax error before `;'
x.cc:2: syntax error before `('
x.cc:3: syntax error before `;'
x.cc:4: syntax error before `('
The patch adds no bison conflicts. It passed a full bootstrap on
i686-pc-linux-gnu on the GCC 3.0 branch and causes no testsuite
regressions.
2001-03-18 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
based on an idea from Joe Buck <jbuck@synopsys.com>
* parse.y (bad_decl, template_arg_list_ignore, arg_list_ignore):
New nonterminals.
(data_def, component_decl): Add reductions to bad_decl.
Gerald
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parse.y,v
retrieving revision 1.214
diff -u -3 -p -r1.214 parse.y
--- parse.y 2001/02/14 13:58:49 1.214
+++ parse.y 2001/03/18 10:37:09
@@ -733,6 +733,7 @@ datadef:
| error ';'
| error '}'
| ';'
+ | bad_decl
;
ctor_initializer_opt:
@@ -2590,6 +2591,8 @@ component_decl:
$$ = finish_member_class_template ($2.t);
finish_template_decl ($1);
}
+ | bad_decl
+ { $$ = NULL_TREE; }
;
component_decl_1:
@@ -3759,6 +3762,26 @@ bad_parm:
cp_error (" perhaps you want `typename %E' to make it a type", $$);
$$ = build_tree_list (integer_type_node, $$);
}
+ ;
+
+bad_decl:
+ IDENTIFIER template_arg_list_ignore IDENTIFIER arg_list_ignore ';'
+ {
+ cp_error("'%D' is used as a type, but is not defined as a type.", $1);
+ $3 = error_mark_node;
+ }
+ ;
+
+template_arg_list_ignore:
+ '<' template_arg_list_opt template_close_bracket
+ { }
+ | /* empty */
+ ;
+
+arg_list_ignore:
+ '(' nonnull_exprlist ')'
+ { }
+ | /* empty */
;
exception_specification_opt: