From patchwork Tue Mar 26 12:09:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 231183 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 BE9BB2C008D for ; Tue, 26 Mar 2013 23:10:15 +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:content-type; q=dns; s=default; b=xaYTqAFvmfcU9fmsXBWsOQVMGajIDPft+UEH/BBBBEt tjmvfrzM0MAQK74QPkzNO5hhdjLoYX9CmAil38LyV9tQC0yXqq39J26XGiQYGLzS cUkr+7XlBqleXVr+yZ8Kof4bMCX8xQbU2TNtMWX6e6SB3UBfNa2yOVx0ldpEwm78 = 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:content-type; s=default; bh=0uKScqxjpHKxtpcjxvPr6DwQ7hU=; b=YOFUKWjjWer14PkKm h0OkEavCN5P3KX5QagVOYCnVuOV5JRIhMn2OSfE5bevKG5Reuz4hgOq/Fe03idoL rTOzJu2L7KDq1NCir1v59ksrA618XgGF7ol07ltS7CDnjlC2uDz8aSLViv73FPXx PGdNJmP/PjPtl07yyxxggxy0ag= Received: (qmail 10284 invoked by alias); 26 Mar 2013 12:10:03 -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 10237 invoked by uid 89); 26 Mar 2013 12:09:56 -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 userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 26 Mar 2013 12:09:53 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2QC9per026982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Mar 2013 12:09:51 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 r2QC9oD7023519 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Mar 2013 12:09:50 GMT Received: from abhmt117.oracle.com (abhmt117.oracle.com [141.146.116.69]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2QC9ovC025342; Tue, 26 Mar 2013 07:09:50 -0500 Received: from [192.168.1.4] (/79.33.222.97) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 Mar 2013 05:09:49 -0700 Message-ID: <51519007.9010708@oracle.com> Date: Tue, 26 Mar 2013 13:09:43 +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: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch/RFC] PR 55951 X-Virus-Found: No Hi, in mainline and 4.8, at variance with 4.7, for: enum { A }; static const char *a[] = { [A] = "a" }; check_array_designated_initializer is called by reshape_init* with ce->index a CONST_DECL, not an INTEGER_CST. Thus I wondered if in such cases it's just matter of using integral_constant_value on it, thus something like the below (which passes testing on x86_64-linux). Thanks, Paolo. ////////////////////// Index: cp/decl.c =================================================================== --- cp/decl.c (revision 197097) +++ cp/decl.c (working copy) @@ -4766,15 +4766,18 @@ check_array_designated_initializer (const construc /* Designated initializers for array elements are not supported. */ if (ce->index) { + tree ce_index = (TREE_CODE (ce->index) == CONST_DECL + ? integral_constant_value (ce->index) : 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"); - else if (TREE_CODE (ce->index) == INTEGER_CST) + else 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"); 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" +};