This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch for throwing ptrs to data members



At the moment, pointers to data members are not caught correctly.
initialize_handler_parm() assumes that __cxa_begin_catch() will return them
by value, but it actually returns them by reference.  Test case attached.

Is the patch below OK (for mainline)?  Bootstraps on i686-pc-linux-gnu with
no check-g++ regressions.

2001-05-29  Richard Sandiford  <rsandifo@redhat.com>

	* except.c (initialize_handler_parm): Expect __cxa_begin_catch to
	return pointers to data members by reference rather than by value.
	* g++.old-deja/g++.other/eh5.C: New testcase.

*** cp/except.c.old	Tue May 29 10:35:48 2001
--- cp/except.c	Tue May 29 10:36:57 2001
*************** initialize_handler_parm (decl, exp)
*** 348,354 ****
       adjusted by value from __cxa_begin_catch.  Others are returned by 
       reference.  */
    init_type = TREE_TYPE (decl);
!   if (TREE_CODE (init_type) != POINTER_TYPE
        && TREE_CODE (init_type) != REFERENCE_TYPE)
      init_type = build_reference_type (init_type);
  
--- 348,354 ----
       adjusted by value from __cxa_begin_catch.  Others are returned by 
       reference.  */
    init_type = TREE_TYPE (decl);
!   if (! TYPE_PTR_P (init_type)
        && TREE_CODE (init_type) != REFERENCE_TYPE)
      init_type = build_reference_type (init_type);
  
*************** initialize_handler_parm (decl, exp)
*** 357,364 ****
  
    /* Since pointers are passed by value, initialize a reference to
       pointer catch parm with the address of the temporary.  */
!   if (TREE_CODE (init_type) == REFERENCE_TYPE 
!       && TREE_CODE (TREE_TYPE (init_type)) == POINTER_TYPE)
      exp = build_unary_op (ADDR_EXPR, exp, 1);
  
    exp = ocp_convert (init_type, exp, CONV_IMPLICIT|CONV_FORCE_TEMP, 0);
--- 357,364 ----
  
    /* Since pointers are passed by value, initialize a reference to
       pointer catch parm with the address of the temporary.  */
!   if (TREE_CODE (init_type) == REFERENCE_TYPE
!       && TYPE_PTR_P (TREE_TYPE (init_type)))
      exp = build_unary_op (ADDR_EXPR, exp, 1);
  
    exp = ocp_convert (init_type, exp, CONV_IMPLICIT|CONV_FORCE_TEMP, 0);
*** testsuite/g++.old-deja/g++.other/eh5.C.old	Tue May 29 10:36:08 2001
--- testsuite/g++.old-deja/g++.other/eh5.C	Tue May 29 10:23:25 2001
***************
*** 0 ****
--- 1,15 ----
+ extern "C" void exit (int);
+ extern "C" void abort (void);
+ struct A { int i; };
+ int main ()
+ {
+   try { throw &A::i; }
+   catch (int A::*p)
+     {
+       if (p == &A::i)
+ 	exit (0);
+       else
+ 	abort ();
+     }
+   abort ();
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]