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]

Re: C++ patch for try/catch in exception members




Chip --

  That's not the right fix, but thanks for reporting the bug.  This
patch fixes both of the problems you reported yesterday, which are
collateral damage from my recent "improvements."

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-08-30  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (start_handler_parms): New function.
	(expand_start_catch_block): Take only one parameter.
	(start_handler_parms): New function.
	* decl.c (start_handler_parms): Define it.
	* except.c (process_start_catch_block): Take only one parameter.
	Don't call grokdeclarator here.
	(expand_start_catch_block): Don't call grokdeclarator here,
	either.
	* parse.y (handler_args): Adjust call to
	expand_start_catch_block.  Use start_handler_parms.
	* pt.c (push_template_decl_real): Make permanent lists have
	permanent elements.
	(tsubst_expr): Adjust calls to expand_start_catch_block
	appropriately.
	* semantics.c (expand_stmt): Likewise.
	
Index: testsuite/g++.old-deja/g++.eh/tmpl5.C
===================================================================
RCS file: tmpl5.C
diff -N tmpl5.C
*** /dev/null	Sat Dec  5 20:30:03 1998
--- tmpl5.C	Mon Aug 30 08:22:55 1999
***************
*** 0 ****
--- 1,13 ----
+ // Build don't link:
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+ 
+ template <class T = int>
+ struct S
+ {
+   void f ()
+     {
+       try {
+       } catch (int) {
+       }
+     }
+ };
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.277
diff -c -p -r1.277 cp-tree.h
*** cp-tree.h	1999/08/29 19:03:26	1.277
--- cp-tree.h	1999/08/30 15:23:00
*************** extern void finish_decl				PROTO((tree, 
*** 2932,2937 ****
--- 2932,2938 ----
  extern void maybe_inject_for_scope_var          PROTO((tree));
  extern void initialize_local_var                PROTO((tree, tree, int));
  extern void expand_static_init			PROTO((tree, tree));
+ extern void start_handler_parms                 PROTO((tree, tree));
  extern int complete_array_type			PROTO((tree, tree, int));
  extern tree build_ptrmemfunc_type		PROTO((tree));
  /* the grokdeclarator prototype is in decl.h */
*************** extern int cp_line_of				PROTO((tree));
*** 3080,3086 ****
  
  /* in except.c */
  extern void init_exception_processing		PROTO((void));
! extern void expand_start_catch_block		PROTO((tree, tree));
  extern void expand_end_catch_block		PROTO((void));
  extern void expand_builtin_throw		PROTO((void));
  extern void expand_start_eh_spec		PROTO((void));
--- 3081,3087 ----
  
  /* in except.c */
  extern void init_exception_processing		PROTO((void));
! extern void expand_start_catch_block		PROTO((tree));
  extern void expand_end_catch_block		PROTO((void));
  extern void expand_builtin_throw		PROTO((void));
  extern void expand_start_eh_spec		PROTO((void));
*************** extern tree begin_function_try_block    
*** 3349,3354 ****
--- 3350,3356 ----
  extern void finish_function_try_block           PROTO((tree));
  extern void finish_function_handler_sequence    PROTO((tree));
  extern tree begin_handler                       PROTO((void));
+ extern void start_handler_parms                 PROTO((tree, tree));
  extern void finish_handler_parms                PROTO((tree));
  extern void finish_handler                      PROTO((tree));
  extern void finish_cleanup                      PROTO((tree, tree));
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.421
diff -c -p -r1.421 decl.c
*** decl.c	1999/08/29 19:03:27	1.421
--- decl.c	1999/08/30 15:23:10
*************** expand_static_init (decl, init)
*** 8317,8322 ****
--- 8317,8343 ----
        static_aggregates = perm_tree_cons (init, decl, static_aggregates);
      }
  }
+ 
+ /* Finish the declaration of a catch-parameter.  */
+ 
+ void
+ start_handler_parms (declspecs, declarator)
+      tree declspecs;
+      tree declarator;
+ {
+   tree decl;
+   if (declspecs)
+     {
+       decl = grokdeclarator (declarator, declspecs, CATCHPARM,
+ 			     1, NULL_TREE);
+       if (decl == NULL_TREE)
+ 	error ("invalid catch parameter");
+     }
+   else
+     decl = NULL_TREE;
+   expand_start_catch_block (decl);
+ }
+ 
  
  /* Make TYPE a complete type based on INITIAL_VALUE.
     Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
Index: cp/except.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/except.c,v
retrieving revision 1.74
diff -c -p -r1.74 except.c
*** except.c	1999/08/26 04:19:52	1.74
--- except.c	1999/08/30 15:23:10
*************** static tree get_eh_caught PROTO((void));
*** 51,57 ****
  static tree get_eh_handlers PROTO((void));
  #endif
  static tree do_pop_exception PROTO((void));
! static void process_start_catch_block PROTO((tree, tree));
  static tree build_eh_type_type_ref PROTO((tree));
  static tree build_terminate_handler PROTO((void));
  static tree alloc_eh_object PROTO((tree));
--- 51,57 ----
  static tree get_eh_handlers PROTO((void));
  #endif
  static tree do_pop_exception PROTO((void));
! static void process_start_catch_block PROTO((tree));
  static tree build_eh_type_type_ref PROTO((tree));
  static tree build_terminate_handler PROTO((void));
  static tree alloc_eh_object PROTO((tree));
*************** build_terminate_handler ()
*** 513,529 ****
     (ie: it ends up as the "else" clause rather than an "else if" clause) */
  
  void
! expand_start_catch_block (declspecs, declarator)
!      tree declspecs, declarator;
  {
-   tree decl;
- 
    if (building_stmt_tree ())
      {
!       if (declspecs)
  	{
! 	  decl = grokdeclarator (declarator, declspecs, CATCHPARM,
! 				 1, NULL_TREE);
  	  if (processing_template_decl)
  	    decl = push_template_decl (decl);
  	  pushdecl (decl);
--- 513,529 ----
     (ie: it ends up as the "else" clause rather than an "else if" clause) */
  
  void
! expand_start_catch_block (decl)
!      tree decl;
  {
    if (building_stmt_tree ())
      {
!       if (decl)
  	{
!  	  /* We must ensure that DECL_CONTEXT is set up before we call
!  	     push_template_decl; that code depends on DECL_CONTEXT
!  	     being set correctly.  */
!  	  DECL_CONTEXT (decl) = current_function_decl;
  	  if (processing_template_decl)
  	    decl = push_template_decl (decl);
  	  pushdecl (decl);
*************** expand_start_catch_block (declspecs, dec
*** 535,541 ****
    if (! doing_eh (1))
      return;
  
!   process_start_catch_block (declspecs, declarator);
  }
  
  /* This function performs the expand_start_catch_block functionality for 
--- 535,541 ----
    if (! doing_eh (1))
      return;
  
!   process_start_catch_block (decl);
  }
  
  /* This function performs the expand_start_catch_block functionality for 
*************** expand_start_catch_block (declspecs, dec
*** 544,570 ****
     nothing additional. */
  
  static void 
! process_start_catch_block (declspecs, declarator)
!      tree declspecs, declarator;
  {
-   tree decl = NULL_TREE;
    tree init;
  
    /* Create a binding level for the eh_info and the exception object
       cleanup.  */
    pushlevel (0);
    expand_start_bindings (0);
- 
  
!   if (declspecs)
!     {
!       decl = grokdeclarator (declarator, declspecs, CATCHPARM, 1, NULL_TREE);
! 
!       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)
      start_catch_handler (build_eh_type_type_ref (TREE_TYPE (decl)));
--- 544,561 ----
     nothing additional. */
  
  static void 
! process_start_catch_block (decl)
!      tree decl;
  {
    tree init;
  
    /* Create a binding level for the eh_info and the exception object
       cleanup.  */
    pushlevel (0);
    expand_start_bindings (0);
  
!   if (decl && !complete_ptr_ref_or_void_ptr_p (TREE_TYPE (decl), NULL_TREE))
!     decl = NULL_TREE;
  
    if (decl)
      start_catch_handler (build_eh_type_type_ref (TREE_TYPE (decl)));
*************** expand_end_eh_spec (raises)
*** 701,707 ****
    int count = 0;
  
    expand_start_all_catch ();
!   expand_start_catch_block (NULL_TREE, NULL_TREE);
  
    /* Build up an array of type_infos.  */
    for (; raises && TREE_VALUE (raises); raises = TREE_CHAIN (raises))
--- 692,698 ----
    int count = 0;
  
    expand_start_all_catch ();
!   expand_start_catch_block (NULL_TREE);
  
    /* Build up an array of type_infos.  */
    for (; raises && TREE_VALUE (raises); raises = TREE_CHAIN (raises))
Index: cp/parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.136
diff -c -p -r1.136 parse.y
*** parse.y	1999/08/28 21:45:28	1.136
--- parse.y	1999/08/30 15:23:17
*************** type_specifier_seq:
*** 3365,3371 ****
  
  handler_args:
  	  '(' ELLIPSIS ')'
! 		{ expand_start_catch_block (NULL_TREE, NULL_TREE); }
  	/* This doesn't allow reference parameters, the below does.
  	| '(' type_specifier_seq absdcl ')'
  		{ check_for_new_type ("inside exception declarations", $2);
--- 3365,3371 ----
  
  handler_args:
  	  '(' ELLIPSIS ')'
! 		{ expand_start_catch_block (NULL_TREE); }
  	/* This doesn't allow reference parameters, the below does.
  	| '(' type_specifier_seq absdcl ')'
  		{ check_for_new_type ("inside exception declarations", $2);
*************** handler_args:
*** 3381,3389 ****
  		  expand_start_catch_block ($2.t, $3); }
  	This allows reference parameters...  */
  	| '(' parm ')'
! 		{ check_for_new_type ("inside exception declarations", $2);
! 		  expand_start_catch_block (TREE_PURPOSE ($2.t),
! 					    TREE_VALUE ($2.t)); }
  	;
  
  label_colon:
--- 3381,3391 ----
  		  expand_start_catch_block ($2.t, $3); }
  	This allows reference parameters...  */
  	| '(' parm ')'
! 		{ 
! 		  check_for_new_type ("inside exception declarations", $2);
! 		  start_handler_parms (TREE_PURPOSE ($2.t),
! 				       TREE_VALUE ($2.t));
! 		}
  	;
  
  label_colon:
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.344
diff -c -p -r1.344 pt.c
*** pt.c	1999/08/30 05:22:45	1.344
--- pt.c	1999/08/30 15:23:23
*************** push_template_decl_real (decl, is_friend
*** 2599,2605 ****
    if (primary)
      DECL_PRIMARY_TEMPLATE (tmpl) = tmpl;
  
!   info = perm_tree_cons (tmpl, args, NULL_TREE);
  
    if (DECL_IMPLICIT_TYPEDEF_P (decl))
      {
--- 2599,2605 ----
    if (primary)
      DECL_PRIMARY_TEMPLATE (tmpl) = tmpl;
  
!   info = perm_tree_cons (tmpl, copy_to_permanent (args), NULL_TREE);
  
    if (DECL_IMPLICIT_TYPEDEF_P (decl))
      {
*************** tsubst_expr (t, args, complain, in_decl)
*** 7465,7478 ****
        lineno = STMT_LINENO (t);
        stmt = begin_handler ();
        if (HANDLER_PARMS (t))
! 	{
! 	  tree d = HANDLER_PARMS (t);
! 	  expand_start_catch_block
! 	    (tsubst (TREE_OPERAND (d, 1), args, complain, in_decl),
! 	     tsubst (TREE_OPERAND (d, 0), args, complain, in_decl));
! 	}
        else
! 	expand_start_catch_block (NULL_TREE, NULL_TREE);
        finish_handler_parms (stmt);
        tsubst_expr (HANDLER_BODY (t), args, complain, in_decl);
        finish_handler (stmt);
--- 7465,7475 ----
        lineno = STMT_LINENO (t);
        stmt = begin_handler ();
        if (HANDLER_PARMS (t))
! 	expand_start_catch_block
! 	  (tsubst (DECL_STMT_DECL (HANDLER_PARMS (t)), 
! 		   args, complain, in_decl));
        else
! 	expand_start_catch_block (NULL_TREE);
        finish_handler_parms (stmt);
        tsubst_expr (HANDLER_BODY (t), args, complain, in_decl);
        finish_handler (stmt);
Index: cp/semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.68
diff -c -p -r1.68 semantics.c
*** semantics.c	1999/08/29 19:03:31	1.68
--- semantics.c	1999/08/30 15:23:24
*************** expand_stmt (t)
*** 2182,2194 ****
        lineno = STMT_LINENO (t);
        begin_handler ();
        if (HANDLER_PARMS (t))
! 	{
! 	  tree d = HANDLER_PARMS (t);
! 	  expand_start_catch_block (TREE_OPERAND (d, 1),
! 				    TREE_OPERAND (d, 0));
! 	}
        else
! 	expand_start_catch_block (NULL_TREE, NULL_TREE);
        finish_handler_parms (NULL_TREE);
        expand_stmt (HANDLER_BODY (t));
        finish_handler (NULL_TREE);
--- 2182,2190 ----
        lineno = STMT_LINENO (t);
        begin_handler ();
        if (HANDLER_PARMS (t))
! 	expand_start_catch_block (DECL_STMT_DECL (HANDLER_PARMS (t)));
        else
! 	expand_start_catch_block (NULL_TREE);
        finish_handler_parms (NULL_TREE);
        expand_stmt (HANDLER_BODY (t));
        finish_handler (NULL_TREE);

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