From patchwork Wed May 30 14:44:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 161985 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 0DC2FB6FFE for ; Thu, 31 May 2012 00:45:16 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1338993917; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=wlBRMjt /6tcOI1Ov+cHDIFXnO5E=; b=RufbQ/xbwAWb+JrsZYtPQBOQ21jg/LEfGSr0b46 kAePZq5NLPn27Ir4gxlb3ulDlI/rSAPcFBIddJXqCXj3j+yta2y6+QbHpZIJajv/ PTG+KJxxmddjbEtmiImpElVuFoa+XZqwFREevY4C9qXV31XbH5YIu9INnZiu+myw F3CU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Et3fRTGMGDTpn9B533+i86OnayPfNKNmi9wEdcfU1OmALMWpPvSV7jAIFPBw2a GCnikY0uS2/Wgxd0ps1tIqO4CpNd/Xz7YXfV3LoK4pIpw+5Eoi25XEfATffkGeLl xlm5DgGuaKi8mD0WVz00leAXDqTqV31RYDjrh75ez/gl4=; Received: (qmail 31075 invoked by alias); 30 May 2012 14:45:12 -0000 Received: (qmail 31065 invoked by uid 22791); 30 May 2012 14:45:10 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Wed, 30 May 2012 14:44:57 +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 q4UEiv1H031581 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 30 May 2012 10:44:57 -0400 Received: from [10.3.113.58] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q4UEiucn028077 for ; Wed, 30 May 2012 10:44:57 -0400 Message-ID: <4FC63267.9070700@redhat.com> Date: Wed, 30 May 2012 10:44:55 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/53356 (C++11 ICE with new) 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 code in build_new_1 already knows how to handle an initializer that it was unable to stabilize, but the logic was backwards in a critical place. I'm surprised this typo hasn't been hit before since it was introduced in 2006... Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit b2e577b5a53a4c49bb3eea682e2c1dee86c27316 Author: Jason Merrill Date: Wed May 30 09:29:37 2012 -0400 PR c++/53356 * tree.c (stabilize_init): Side effects make the init unstable. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 236180d..897d4d7 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3458,7 +3458,7 @@ stabilize_init (tree init, tree *initp) /* The initialization is being performed via a bitwise copy -- and the item copied may have side effects. */ - return TREE_SIDE_EFFECTS (init); + return !TREE_SIDE_EFFECTS (init); } /* Like "fold", but should be used whenever we might be processing the diff --git a/gcc/testsuite/g++.dg/init/new33.C b/gcc/testsuite/g++.dg/init/new33.C new file mode 100644 index 0000000..18da79e --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new33.C @@ -0,0 +1,11 @@ +// PR c++/53356 +// { dg-do compile } + +struct A {}; +struct B { operator const A & () const; }; +struct C { operator const A & () const; C (); }; +struct D { operator const A & () const; D (); ~D (); }; + +A *foo () { return new A (B ()); } +A *bar () { return new A (C ()); } +A *baz () { return new A (D ()); }