From patchwork Wed Mar 16 20:00:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 87298 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 D2939B6FAC for ; Thu, 17 Mar 2011 07:00:18 +1100 (EST) Received: (qmail 20585 invoked by alias); 16 Mar 2011 20:00:15 -0000 Received: (qmail 20561 invoked by uid 22791); 16 Mar 2011 20:00:13 -0000 X-SWARE-Spam-Status: No, hits=-6.3 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; Wed, 16 Mar 2011 20:00:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2GK03TX017879 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Mar 2011 16:00:03 -0400 Received: from [127.0.0.1] (ovpn-113-145.phx2.redhat.com [10.3.113.145]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2GK02oj002993 for ; Wed, 16 Mar 2011 16:00:02 -0400 Message-ID: <4D8116C1.8080602@redhat.com> Date: Wed, 16 Mar 2011 16:00:01 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48132 (ICE with constexpr and array) 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 Jakub was right that we were failing to add indices to the array CONSTRUCTOR along this code path. It seems appropriate to add them earlier, in reshape_init, like we do for classes, so this patch fixes the bug that way. Tested x86_64-pc-linux-gnu, applying to trunk. Also OK for 4.6.0? The risk is that something else not caught by the testsuite could be confused by adding the indices slightly sooner, but that seems unlikely. commit 4d360926bf71c078e6c6962b7aee997c2e5974e6 Author: Jason Merrill Date: Wed Mar 16 15:15:56 2011 -0400 PR c++/48132 * decl.c (check_array_designated_initializer): Allow integer index. (reshape_init_array_1): Set index on the elements. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f9d90ad..3139ad8 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4596,6 +4596,9 @@ check_array_designated_initializer (const constructor_elt *ce) if (ce->index == error_mark_node) error ("name used in a GNU-style designated " "initializer for an array"); + else if (TREE_CODE (ce->index) == INTEGER_CST) + /* An index added by reshape_init. */ + return true; else { gcc_assert (TREE_CODE (ce->index) == IDENTIFIER_NODE); @@ -4899,7 +4902,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d) elt_init = reshape_init_r (elt_type, d, /*first_initializer_p=*/false); if (elt_init == error_mark_node) return error_mark_node; - CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), NULL_TREE, elt_init); + CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), + size_int (index), elt_init); } return new_init; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array3.C new file mode 100644 index 0000000..145a430 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array3.C @@ -0,0 +1,14 @@ +// PR c++/48132 +// { dg-options -std=c++0x } + +struct C +{ + constexpr C (int x) : c (x) {} + int c; +}; + +void +foo () +{ + C a[] = { C (0) }; +}