From patchwork Thu Jun 30 23:59:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 102846 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 9E228B6F54 for ; Fri, 1 Jul 2011 10:00:05 +1000 (EST) Received: (qmail 5310 invoked by alias); 1 Jul 2011 00:00:02 -0000 Received: (qmail 5219 invoked by uid 22791); 1 Jul 2011 00:00:01 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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; Thu, 30 Jun 2011 23:59:47 +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 p5UNxlfh025183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 30 Jun 2011 19:59:47 -0400 Received: from [127.0.0.1] (ovpn-113-39.phx2.redhat.com [10.3.113.39]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5UNxkmE021372 for ; Thu, 30 Jun 2011 19:59:47 -0400 Message-ID: <4E0D0DF2.603@redhat.com> Date: Thu, 30 Jun 2011 19:59:46 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49355 (ICE with new T({""})) 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 The problem here was that stabilize_init called from build_new_1 wasn't doing anything to stabilize the elements of a CONSTRUCTOR, so the allocator argument wasn't preevaluated, and due to the cleanup for the data pointer its cleanup wasn't associated with the CLEANUP_POINT_EXPR, leading to a crash. Tested x86_64-pc-linux-gnu, applying to trunk. commit 5e42b54f626d5796ecb21ea2c78a7be2699a4c0a Author: Jason Merrill Date: Thu Jun 30 17:48:10 2011 -0400 PR c++/49355 * tree.c (stabilize_init): Handle aggregate initialization. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index c50751f..678c7ef 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3291,10 +3291,18 @@ stabilize_init (tree init, tree *initp) t = TARGET_EXPR_INITIAL (t); if (TREE_CODE (t) == COMPOUND_EXPR) t = expr_last (t); - if (TREE_CODE (t) == CONSTRUCTOR - && EMPTY_CONSTRUCTOR_P (t)) - /* Default-initialization. */ - return true; + if (TREE_CODE (t) == CONSTRUCTOR) + { + /* Aggregate initialization: stabilize each of the field + initializers. */ + unsigned i; + tree value; + bool good = true; + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, value) + if (!stabilize_init (value, initp)) + good = false; + return good; + } /* If the initializer is a COND_EXPR, we can't preevaluate anything. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist54.C b/gcc/testsuite/g++.dg/cpp0x/initlist54.C new file mode 100644 index 0000000..cdb2961 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist54.C @@ -0,0 +1,13 @@ +// PR c++/49355 +// { dg-options -std=c++0x } + +#include + +struct T { + std::string foobar; +}; + +int main() +{ + T* x = new T({""}); +}