exception handling bug?

Jason Merrill jason@cygnus.com
Wed Nov 26 06:10:00 GMT 1997


>>>>> Marc Lehmann <pcg@goof.com> writes:

> struct E {
>    int x;
>    E(int i) { x = i; };
> };

> int main()
> {
>    try {
>       E *p = new E(5);
>       throw p;
>    }
   
>    catch (E *&e) {
>       printf ("address of e is %d\n", (long)e);
>    }
> }

> prints "address of e is 5" instead of the *address* of e. I'm
> no exception expert, but IMHO this should print the contents of "p"
> instead.

Here's a fix:

Wed Nov 26 01:11:24 1997  Jason Merrill  <jason@yorick.cygnus.com>

	* except.c (expand_start_catch_block): Fix catching a reference
	to pointer.

Index: except.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/except.c,v
retrieving revision 1.135
diff -c -r1.135 except.c
*** except.c	1997/11/25 06:15:40	1.135
--- except.c	1997/11/26 09:11:40
***************
*** 614,619 ****
--- 614,626 ----
  	init_type = build_reference_type (init_type);
  
        exp = get_eh_value ();
+ 
+       /* Since pointers are passed by value, initialize a reference to
+ 	 pointer catch parm with the address of the value slot.  */
+       if (TREE_CODE (init_type) == REFERENCE_TYPE
+ 	  && TREE_CODE (TREE_TYPE (init_type)) == POINTER_TYPE)
+ 	exp = build_unary_op (ADDR_EXPR, exp, 1);
+ 
        exp = expr_tree_cons (NULL_TREE,
  		       build_eh_type_type (TREE_TYPE (decl)),
  		       expr_tree_cons (NULL_TREE,



More information about the Gcc mailing list