From patchwork Sat Nov 5 03:23:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 123815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 07D58B70D1 for ; Sat, 5 Nov 2011 14:23:30 +1100 (EST) Received: (qmail 8494 invoked by alias); 5 Nov 2011 03:23:27 -0000 Received: (qmail 8483 invoked by uid 22791); 5 Nov 2011 03:23:26 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 05 Nov 2011 03:23:12 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA53NBvm029772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Nov 2011 23:23:11 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pA53NBqC020028 for ; Fri, 4 Nov 2011 23:23:11 -0400 Received: from [0.0.0.0] (ovpn-113-72.phx2.redhat.com [10.3.113.72]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pA53N9Zf027820 for ; Fri, 4 Nov 2011 23:23:10 -0400 Message-ID: <4EB4AC1D.9040303@redhat.com> Date: Fri, 04 Nov 2011 23:23:09 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: Re: C++ PATCH for c++/48370 (extending lifetime of temps in aggregate initialization) References: <4EB36120.3060603@redhat.com> In-Reply-To: <4EB36120.3060603@redhat.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. commit 376093f30953db1fc7b4537f7ca9253dea91c8a3 Author: Jason Merrill 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; }