C++ PATCH: check catch parameter
Nathan Sidwell
nathan@acm.org
Wed Jun 30 23:15:00 GMT 1999
mark@codesourcery.com wrote:
> This is fine, except that you duplicated a bunch of code. Please
> break it out into something like incomplete_or_void_star_p () or
> something, and put the duplicated code there. Will improve
> readability as well!
Good idea, I have installed the attached, which does this.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
Index: egcs/gcc/cp/ChangeLog
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/ChangeLog,v
retrieving revision 1.1093
diff -c -3 -p -r1.1093 ChangeLog
*** ChangeLog 1999/06/07 13:28:03 1.1093
--- ChangeLog 1999/06/08 12:07:53
***************
*** 1,3 ****
--- 1,10 ----
+ 1999-06-08 Nathan Sidwell <nathan@acm.org>
+
+ * except.c (complete_ptr_ref_or_void_ptr_p): New function, broken out
+ of ...
+ (build_throw): ... here. Call it.
+ (process_start_catch_block): Call it.
+
1999-06-07 Mark Mitchell <mark@codesourcery.com>
* search.c (convert_pointer_to_single_level): Reimplement without
Index: egcs/gcc/cp/except.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/except.c,v
retrieving revision 1.64
diff -c -3 -p -r1.64 except.c
*** except.c 1999/06/04 01:31:35 1.64
--- except.c 1999/06/08 12:07:55
*************** static void process_start_catch_block PR
*** 62,67 ****
--- 62,68 ----
static tree build_eh_type_type_ref PROTO((tree));
static tree build_terminate_handler PROTO((void));
static tree alloc_eh_object PROTO((tree));
+ static int complete_ptr_ref_or_void_ptr_p PROTO((tree, tree));
#if 0
/* This is the startup, and finish stuff per exception table. */
*************** process_start_catch_block (declspecs, de
*** 625,630 ****
--- 626,633 ----
if (decl == NULL_TREE)
error ("invalid catch parameter");
+ else if (!complete_ptr_ref_or_void_ptr_p (TREE_TYPE (decl), NULL_TREE))
+ decl = NULL_TREE;
}
if (decl)
*************** build_throw (e)
*** 1155,1180 ****
if (e != NULL_TREE)
{
! tree core;
! int is_ptr;
!
! /* Cannot throw an incomplete type. */
! e = require_complete_type (e);
! if (e == error_mark_node)
! return e;
!
! /* Or a pointer or ref to one, other than cv void *. */
! core = TREE_TYPE (e);
! is_ptr = TREE_CODE (core) == POINTER_TYPE;
! if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE)
! {
! core = TREE_TYPE (core);
!
! if (is_ptr && same_type_p (TYPE_MAIN_VARIANT (core), void_type_node))
! /* OK */;
! else if (!complete_type_or_else (core, NULL_TREE))
! return error_mark_node;
! }
}
e = build1 (THROW_EXPR, void_type_node, e);
--- 1158,1165 ----
if (e != NULL_TREE)
{
! if (!complete_ptr_ref_or_void_ptr_p (TREE_TYPE (e), e))
! return error_mark_node;
}
e = build1 (THROW_EXPR, void_type_node, e);
*************** build_throw (e)
*** 1183,1185 ****
--- 1168,1202 ----
return e;
}
+
+ /* Make sure TYPE is complete, pointer to complete, reference to
+ complete, or pointer to cv void. Issue diagnostic on failure.
+ Return the zero on failure and non-zero on success. FROM can be
+ the expr or decl from whence TYPE came, if available. */
+
+ static int
+ complete_ptr_ref_or_void_ptr_p (type, from)
+ tree type;
+ tree from;
+ {
+ int is_ptr;
+
+ /* Check complete. */
+ type = complete_type_or_else (type, from);
+ if (!type)
+ return 0;
+
+ /* Or a pointer or ref to one, or cv void *. */
+ is_ptr = TREE_CODE (type) == POINTER_TYPE;
+ if (is_ptr || TREE_CODE (type) == REFERENCE_TYPE)
+ {
+ tree core = TREE_TYPE (type);
+
+ if (is_ptr && same_type_p (TYPE_MAIN_VARIANT (core), void_type_node))
+ /* OK */;
+ else if (!complete_type_or_else (core, from))
+ return 0;
+ }
+ return 1;
+ }
+
More information about the Gcc-patches
mailing list