C++ PATCH for better error handling
Mark Mitchell
markATcodesourcery.com
Fri Sep 17 00:33:00 GMT 1999
This patch improves error-recovery a little, and removes the
(confusing) use of poplevel where poplevel_class was intended.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-09-17 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (poplevel_class): Declare.
* class.c (popclass): Use poplevel_class, not poplevel.
* decl.c (poplevel_class): Don't make it static. Don't return a
value.
(poplevel): Don't call poplevel_class; abort in a class
binding level is seen.
* semantics.c (finish_translation_unit): Use pop_everything.
* parse.y (member_init): Allow errors.
(pending_inline): Call finish_function.
* parse.c: Regenerated.
* Makefile.in (CONFLICTS): Adjust.
Index: testsuite/g++.old-deja/g++.oliva/ctor1.C
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.oliva/ctor1.C,v
retrieving revision 1.2
diff -c -p -r1.2 ctor1.C
*** ctor1.C 1999/09/04 15:09:04 1.2
--- ctor1.C 1999/09/17 07:31:11
*************** struct B {
*** 15,19 ****
struct C {
// The error message below says it is within A::B::m()!
! void n() {} // gets bogus error - XFAIL *-*-*
};
--- 15,19 ----
struct C {
// The error message below says it is within A::B::m()!
! void n() {}
};
Index: testsuite/g++.old-deja/g++.brendan/crash9.C
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.brendan/crash9.C,v
retrieving revision 1.2
diff -c -p -r1.2 crash9.C
*** crash9.C 1998/12/16 21:24:28 1.2
--- crash9.C 1999/09/17 07:27:40
*************** protected:
*** 15,24 ****
SimQuery::SimQuery():scaling(A) {}// ERROR - .*
! SimQuery::~SimQuery() {}// ERROR -
int SimQuery::SetMeshFile(char name[])
! {// ERROR -
mesh = new C;// ERROR - .*
return 0; // needed to avoid warning of reaching end of non-void fn
}
--- 15,24 ----
SimQuery::SimQuery():scaling(A) {}// ERROR - .*
! SimQuery::~SimQuery() {}
int SimQuery::SetMeshFile(char name[])
! {
mesh = new C;// ERROR - .*
return 0; // needed to avoid warning of reaching end of non-void fn
}
Index: cp/class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.184
diff -c -p -r1.184 class.c
*** class.c 1999/09/09 06:16:30 1.184
--- class.c 1999/09/17 07:27:44
*************** invalidate_class_lookup_cache ()
*** 4573,4579 ****
void
popclass ()
{
! poplevel (1, 0, 0);
/* Since poplevel_class does the popping of class decls nowadays,
this really only frees the obstack used for these decls. */
pop_class_decls ();
--- 4573,4579 ----
void
popclass ()
{
! poplevel_class ();
/* Since poplevel_class does the popping of class decls nowadays,
this really only frees the obstack used for these decls. */
pop_class_decls ();
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.305
diff -c -p -r1.305 cp-tree.h
*** cp-tree.h 1999/09/14 00:50:06 1.305
--- cp-tree.h 1999/09/17 07:27:47
*************** extern void insert_block PROTO((tree))
*** 3120,3125 ****
--- 3120,3126 ----
extern void add_block_current_level PROTO((tree));
extern void set_block PROTO((tree));
extern void pushlevel_class PROTO((void));
+ extern void poplevel_class PROTO((void));
extern void print_binding_stack PROTO((void));
extern void print_binding_level PROTO((struct binding_level *));
extern void push_namespace PROTO((tree));
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.452
diff -c -p -r1.452 decl.c
*** decl.c 1999/09/16 01:20:42 1.452
--- decl.c 1999/09/17 07:27:56
*************** static tree record_builtin_java_type PRO
*** 158,164 ****
static const char *tag_name PROTO((enum tag_types code));
static void find_class_binding_level PROTO((void));
static struct binding_level *innermost_nonclass_level PROTO((void));
- static tree poplevel_class PROTO((void));
static void warn_about_implicit_typename_lookup PROTO((tree, tree));
static int walk_namespaces_r PROTO((tree, walk_namespaces_fn, void *));
static int walk_globals_r PROTO((tree, void *));
--- 158,163 ----
*************** poplevel (keep, reverse, functionbody)
*** 1201,1208 ****
int block_previously_created;
int leaving_for_scope;
! if (current_binding_level->parm_flag == 2)
! return poplevel_class ();
my_friendly_assert (!current_binding_level->class_shadowed,
19990414);
--- 1200,1207 ----
int block_previously_created;
int leaving_for_scope;
! my_friendly_assert (current_binding_level->parm_flag != 2,
! 19990916);
my_friendly_assert (!current_binding_level->class_shadowed,
19990414);
*************** pushlevel_class ()
*** 1576,1582 ****
/* ...and a poplevel for class declarations. */
! static tree
poplevel_class ()
{
register struct binding_level *level = class_binding_level;
--- 1575,1581 ----
/* ...and a poplevel for class declarations. */
! void
poplevel_class ()
{
register struct binding_level *level = class_binding_level;
*************** poplevel_class ()
*** 1652,1659 ****
#endif /* defined(DEBUG_CP_BINDING_LEVELS) */
pop_binding_level ();
-
- return NULL_TREE;
}
/* We are entering the scope of a class. Clear IDENTIFIER_CLASS_VALUE
--- 1651,1656 ----
Index: cp/parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.145
diff -c -p -r1.145 parse.y
*** parse.y 1999/09/10 01:09:05 1.145
--- parse.y 1999/09/17 07:28:03
*************** member_init:
*** 854,859 ****
--- 854,860 ----
| typename_sub LEFT_RIGHT
{ expand_member_init (current_class_ref, TYPE_MAIN_DECL ($1),
void_type_node); }
+ | error
;
identifier:
*************** pending_inline:
*** 2081,2088 ****
process_next_inline ($1);
}
| fn.defpen maybe_return_init error
! { free_after_compilation (current_function);
! current_function = NULL;
process_next_inline ($1); }
;
--- 2082,2089 ----
process_next_inline ($1);
}
| fn.defpen maybe_return_init error
! {
! finish_function (lineno, 2);
process_next_inline ($1); }
;
Index: cp/semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.81
diff -c -p -r1.81 semantics.c
*** semantics.c 1999/09/12 01:12:59 1.81
--- semantics.c 1999/09/17 07:28:04
*************** finish_translation_unit ()
*** 1542,1549 ****
{
/* In case there were missing closebraces,
get us back to the global binding level. */
! while (! toplevel_bindings_p ())
! poplevel (0, 0, 0);
while (current_namespace != global_namespace)
pop_namespace ();
finish_file ();
--- 1542,1548 ----
{
/* In case there were missing closebraces,
get us back to the global binding level. */
! pop_everything ();
while (current_namespace != global_namespace)
pop_namespace ();
finish_file ();
More information about the Gcc-patches
mailing list