]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/48370 (G++ fails to extend reference temporary lifetime in some situations)
authorJason Merrill <jason@redhat.com>
Sat, 5 Nov 2011 03:28:05 +0000 (23:28 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 5 Nov 2011 03:28:05 +0000 (23:28 -0400)
PR c++/48370
* decl.c (cp_finish_decl): Run cleanups in the right order.

From-SVN: r181001

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/lifetime1.C

index ffb085c4d9e81a8df87d5db66d33a78411573015..6c68d8798da02c6ddaa2422ba890a4070d9f830c 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/48370
+       * decl.c (cp_finish_decl): Run cleanups in the right order.
+
 2011-11-04  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR c++/50608
index 50c45de863315d70f6fc4efbf0746a20384cd9d9..65413df26203b03283c7f209007b54704302eb7d 100644 (file)
@@ -5907,7 +5907,8 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
                tree asmspec_tree, int flags)
 {
   tree type;
-  VEC(tree,gc) *cleanups = NULL;
+  VEC(tree,gc) *cleanups = make_tree_vector ();
+  unsigned i; tree t;
   const char *asmspec = NULL;
   int was_readonly = 0;
   bool var_definition_p = false;
@@ -6315,12 +6316,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 
   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
      reference, insert it in the statement-tree now.  */
-  if (cleanups)
-    {
-      unsigned i; tree t;
-      FOR_EACH_VEC_ELT_REVERSE (tree, cleanups, i, t)
-       push_cleanup (decl, t, false);
-    }
+  FOR_EACH_VEC_ELT (tree, cleanups, i, t)
+    push_cleanup (decl, t, false);
+  release_tree_vector (cleanups);
 
   if (was_readonly)
     TREE_READONLY (decl) = 1;
index 218a9d34a5924b1e901431463405f625114a7ec9..2e05a080ccb6f44d9bd59da62f890b5b6bfa8c37 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/48370
+       * g++.dg/init/lifetime1.C: Test cleanup order.
+
 2011-11-04  Eric Botcazou  <ebotcazou@adacore.com>
 
        * g++.dg/other/offsetof7.C: New test.
index 38e25ec991a00637d5cff75cc55fcb1e04302a75..57f8c62179ade3cdb3f4d2f1ef06e30f444b21d6 100644 (file)
@@ -2,12 +2,13 @@
 // { dg-do run }
 
 extern "C" void abort();
-bool ok;
+
+int last = 4;
 
 struct A {
   int i;
   A(int i): i(i) { }
-  ~A() { if (!ok) abort(); }
+  ~A() { if (i > last) abort(); last = i; }
 };
 
 struct D { int i; };
@@ -25,5 +26,4 @@ struct C
 int main()
 {
   C c = { 1, B(2), E(3) };
-  ok = true;
 }