From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH for c++/48370 (extending lifetime of temps in aggregate initialization)
Date: Sat, 05 Nov 2011 04:42:00 -0000 [thread overview]
Message-ID: <4EB4AC1D.9040303@redhat.com> (raw)
In-Reply-To: <4EB36120.3060603@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 174 bytes --]
While working on a followup, I noticed that this patch runs temporary
cleanups in the wrong order. Fixed (and tested) thus.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 48370-2.patch --]
[-- Type: text/x-patch, Size: 1720 bytes --]
commit 376093f30953db1fc7b4537f7ca9253dea91c8a3
Author: Jason Merrill <jason@redhat.com>
Date: Fri Nov 4 16:32:47 2011 -0400
PR c++/48370
* decl.c (cp_finish_decl): Run cleanups in the right order.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 50c45de..65413df 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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;
diff --git a/gcc/testsuite/g++.dg/init/lifetime1.C b/gcc/testsuite/g++.dg/init/lifetime1.C
index 38e25ec..57f8c62 100644
--- a/gcc/testsuite/g++.dg/init/lifetime1.C
+++ b/gcc/testsuite/g++.dg/init/lifetime1.C
@@ -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;
}
next prev parent reply other threads:[~2011-11-05 3:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-04 5:55 Jason Merrill
2011-11-05 4:42 ` Jason Merrill [this message]
2011-11-07 18:08 ` Jason Merrill
2012-06-13 5:50 ` H.J. Lu
2012-08-07 19:56 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EB4AC1D.9040303@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).