From patchwork Fri Jan 21 22:30:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 79959 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 48D33B6EED for ; Sat, 22 Jan 2011 09:30:42 +1100 (EST) Received: (qmail 19298 invoked by alias); 21 Jan 2011 22:30:37 -0000 Received: (qmail 19288 invoked by uid 22791); 21 Jan 2011 22:30:33 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, 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; Fri, 21 Jan 2011 22:30:08 +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.13.8/8.13.8) with ESMTP id p0LMU6xL012664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Jan 2011 17:30:07 -0500 Received: from [127.0.0.1] (ovpn-113-71.phx2.redhat.com [10.3.113.71]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0LMU6Af005911 for ; Fri, 21 Jan 2011 17:30:06 -0500 Message-ID: <4D3A08EE.9090603@redhat.com> Date: Fri, 21 Jan 2011 17:30:06 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/47041 (crash with c++0x and -fno-elide-constructors) 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 It puzzles me that people actually use -fno-elide-constructors, but as long as it's in the compiler it ought to work, and it's probably possible to run into this bug without that flag: a trivial copy ctor/op= is implemented with a single big assignment rather than memberwise copy, so we need to handle that case. Tested x86_64-pc-linux-gnu, applied to trunk. commit ce3d514493c3e54adc5ce2889e6af75692289793 Author: Jason Merrill Date: Fri Jan 21 16:10:18 2011 -0500 PR c++/47041 * semantics.c (build_constexpr_constructor_member_initializers): Handle trivial copy. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fa35d4a..fae9948 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5605,7 +5605,20 @@ build_constexpr_constructor_member_initializers (tree type, tree body) body = STATEMENT_LIST_HEAD (body)->stmt; body = BIND_EXPR_BODY (body); if (TREE_CODE (body) == CLEANUP_POINT_EXPR) - ok = build_data_member_initialization (body, &vec); + { + body = TREE_OPERAND (body, 0); + if (TREE_CODE (body) == EXPR_STMT) + body = TREE_OPERAND (body, 0); + if (TREE_CODE (body) == INIT_EXPR + && (same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (TREE_OPERAND (body, 0)), + current_class_type))) + { + /* Trivial copy. */ + return TREE_OPERAND (body, 1); + } + ok = build_data_member_initialization (body, &vec); + } else if (TREE_CODE (body) == STATEMENT_LIST) { tree_stmt_iterator i; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C new file mode 100644 index 0000000..4f86f73 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C @@ -0,0 +1,9 @@ +// PR c++/47041 +// { dg-options "-std=c++0x -fno-elide-constructors" } + +struct S +{ + int i; +}; + +S s = S ();