From patchwork Tue Mar 26 15:00:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 231251 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 97CFC2C0084 for ; Wed, 27 Mar 2013 02:01:01 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=uBDo5d5Rggd5JRB8X N4Kr6b+3SfH66Znu2uIdHSj+sOkZSJb9AwDPbFyL9fKIkGmhpQo1aXW0Mza+oH1G 3HFw888T3Cyo5HAmV0a0KPZoO/YT6k6qsHHcNqczkMU+/39AZbYp/3gZdNvlUvzV ZVYFBB4dyOZ/jQFZdlnIxE8I4c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=pE1lO6HyWiz58DzuY/FvfbU x85U=; b=h0ussyKDIVFJwBdCo/hBNBy6l3LzeV4bVgA8U4lCSStYiK1n+hpRiqd ItalTnyvD+Hs2KiaR0ZZ6Ac+f93H4wqrHX0ZHEjYOdCoTkhwgSVSSFaq03JgHNE2 wJMIkSx8lu0RUERd8eQEapBbbxoJTUVhBCGlozbIu3LPpnoRqEyI= Received: (qmail 19222 invoked by alias); 26 Mar 2013 15:00:30 -0000 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 Received: (qmail 19181 invoked by uid 89); 26 Mar 2013 15:00:22 -0000 X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 26 Mar 2013 15:00:15 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2QF0C4g027632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Mar 2013 15:00:13 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2QF0Bn9017529 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Mar 2013 15:00:11 GMT Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2QF0BKe004167; Tue, 26 Mar 2013 10:00:11 -0500 Received: from [192.168.1.4] (/79.33.222.97) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 Mar 2013 08:00:10 -0700 Message-ID: <5151B7F8.6060503@oracle.com> Date: Tue, 26 Mar 2013 16:00:08 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch/RFC] PR 55951 References: <51519007.9010708@oracle.com> <51519560.8080306@redhat.com> <51519FF8.7040500@oracle.com> <5151AD4D.705@redhat.com> <5151AD84.9060400@redhat.com> In-Reply-To: <5151AD84.9060400@redhat.com> X-Virus-Found: No Hi, On 03/26/2013 03:15 PM, Jason Merrill wrote: > On 03/26/2013 10:14 AM, Jason Merrill wrote: >> On 03/26/2013 09:17 AM, Paolo Carlini wrote: >>> + if (identifier_p (ce->index)) >>> + { >>> + error ("name %qD used in a GNU-style designated " >>> + "initializer for an array", ce->index); >>> + return false; >>> + } >>> + >>> + tree ce_index = cxx_constant_value (ce->index); >>> + >>> /* The parser only allows identifiers as designated >>> initializers. */ >>> if (ce->index == error_mark_node) >>> error ("name used in a GNU-style designated " >>> "initializer for an array"); >> >> Let's also combine these two instances of the same error. > Or at any rate move the error_mark_node case above cxx_constant_value > as well. Indeed. Thus I'm finishing testing the below. Thanks, Paolo. //////////////////// Index: cp/decl.c =================================================================== --- cp/decl.c (revision 197097) +++ cp/decl.c (working copy) @@ -4769,22 +4769,31 @@ check_array_designated_initializer (const construc /* The parser only allows identifiers as designated initializers. */ 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) { + error ("name used in a GNU-style designated " + "initializer for an array"); + return false; + } + else if (identifier_p (ce->index)) + { + error ("name %qD used in a GNU-style designated " + "initializer for an array", ce->index); + return false; + } + + tree ce_index = cxx_constant_value (ce->index); + + if (TREE_CODE (ce_index) == INTEGER_CST) + { /* A C99 designator is OK if it matches the current index. */ - if (TREE_INT_CST_LOW (ce->index) == index) + if (TREE_INT_CST_LOW (ce_index) == index) return true; else sorry ("non-trivial designated initializers not supported"); } else - { - gcc_assert (identifier_p (ce->index)); - error ("name %qD used in a GNU-style designated " - "initializer for an array", ce->index); - } + gcc_unreachable (); + return false; } Index: testsuite/g++.dg/ext/desig5.C =================================================================== --- testsuite/g++.dg/ext/desig5.C (revision 0) +++ testsuite/g++.dg/ext/desig5.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/55951 + +enum { A }; + +static const char *a[] = { + [A] = "a" +};