]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/8287 (GCC3.2: Destructor called for non-constructed local object)
authorMark Mitchell <mark@codesourcery.com>
Tue, 29 Oct 2002 23:51:12 +0000 (23:51 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 29 Oct 2002 23:51:12 +0000 (23:51 +0000)
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.

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

From-SVN: r58642

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

index eaba75521948e1ca3a1b03a4a5e10a98e5e10e32..dd372fbee1bb8eb57b0cbe997b68f8b1690fa210 100644 (file)
@@ -1,5 +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.
+
        * semantics.c (finish_alignof): Call complete_type before calling
        c_alignof.
        * decl2.c (build_expr_from_tree): Use
index 1b139ffdafb957f55888a2f262b4b6a2c2ed5009..613766253f3be926af91fe2a97d72326908ad616 100644 (file)
@@ -14112,6 +14112,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));
+
   /* And perform cleanups for our bases and members.  */
   perform_base_cleanups ();
 
@@ -14187,14 +14191,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)
index 592de43a95303b30089f6ed499c0fe4e1634986a..4b1531d85f70da858ce138166691aaab4043cf12 100644 (file)
@@ -1,5 +1,8 @@
 2002-10-29  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/8287
+       * g++.dg/init/dtor2.C: New test.
+
        * g++.dg/template/alignof1.C: New test.
 
 2002-10-28  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
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;
+}