C++ PATCH: PR 8287

Mark Mitchell mark@codesourcery.com
Tue Oct 29 16:06:00 GMT 2002


This patch fixes PR 8287, a regression from GCC 2.95.x.

Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.

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

2002-10-29  Mark Mitchell  <mark@codesourcery.com>

	PR c++/8287
	* decl.c (finish_destructor_body): Create the label to jump to
	when returning from a destructor here.
	(finish_function_body): Rather than here.

2002-10-29  Mark Mitchell  <mark@codesourcery.com>

	PR c++/8287
	* g++.dg/init/dtor2.C: New test.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.866.2.36.2.10
diff -c -p -r1.866.2.36.2.10 decl.c
*** cp/decl.c	25 Oct 2002 22:38:05 -0000	1.866.2.36.2.10
--- cp/decl.c	29 Oct 2002 23:16:26 -0000
*************** finish_destructor_body ()
*** 14112,14117 ****
--- 14112,14121 ----
  {
    tree exprstmt;
  
+   /* Any return from a destructor will end up here; that way all base
+      and member cleanups will be run when the function returns.  */
+   add_stmt (build_stmt (LABEL_STMT, dtor_label));
+ 
    /* And perform cleanups for our bases and members.  */
    perform_base_cleanups ();
  
*************** void
*** 14187,14200 ****
  finish_function_body (compstmt)
       tree compstmt;
  {
!   if (processing_template_decl)
!     /* Do nothing now.  */;
!   else if (DECL_DESTRUCTOR_P (current_function_decl))
!     /* Any return from a destructor will end up here.  Put it before the
!        cleanups so that an explicit return doesn't duplicate them.  */
!     add_stmt (build_stmt (LABEL_STMT, dtor_label));
! 
!   /* Close the block; in a destructor, run the member cleanups.  */
    finish_compound_stmt (0, compstmt);
  
    if (processing_template_decl)
--- 14191,14197 ----
  finish_function_body (compstmt)
       tree compstmt;
  {
!   /* Close the block.  */
    finish_compound_stmt (0, compstmt);
  
    if (processing_template_decl)
Index: testsuite/g++.dg/init/dtor2.C
===================================================================
RCS file: testsuite/g++.dg/init/dtor2.C
diff -N testsuite/g++.dg/init/dtor2.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/dtor2.C	29 Oct 2002 23:16:27 -0000
***************
*** 0 ****
--- 1,28 ----
+ // { dg-do run }
+ 
+ extern "C" void abort ();
+ 
+ struct A
+ {
+   ~A();
+ };
+ 
+ A::~A () {
+   abort ();
+ }
+ 
+ struct B
+ {
+   ~B();
+ };
+ 
+ B::~B () {
+   if(true) return;
+   A a;
+ }
+ 
+ int main()
+ {
+   B b;
+   return 0;
+ }



More information about the Gcc-patches mailing list