OSDN Git Service

PR c++/8287
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 Oct 2002 00:05:36 +0000 (00:05 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 Oct 2002 00:05:36 +0000 (00:05 +0000)
* decl.c (finish_destructor_body): Create the label to jump to
when returning from a destructor here.
(finish_function_body): Rather than here.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@58643 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/init/dtor2.C [new file with mode: 0644]

index d9e212a..dba4a0d 100644 (file)
@@ -1,3 +1,10 @@
+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-25  Zack Weinberg  <zack@codesourcery.com>
 
        PR c++/7266
index e3b7b5b..f42c8d3 100644 (file)
@@ -14275,6 +14275,10 @@ finish_destructor_body ()
 {
   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));
+
   /* In a virtual destructor, we must call delete.  */
   if (DECL_VIRTUAL_P (current_function_decl))
     {
@@ -14347,14 +14351,7 @@ void
 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.  */
+  /* Close the block.  */
   finish_compound_stmt (0, compstmt);
 
   if (processing_template_decl)
diff --git a/gcc/testsuite/g++.dg/init/dtor2.C b/gcc/testsuite/g++.dg/init/dtor2.C
new file mode 100644 (file)
index 0000000..56c7cac
--- /dev/null
@@ -0,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;
+}