From patchwork Thu Nov 30 18:19:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 843138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-468268-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="MeUu5WQ7"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ynm0R4tlzz9s03 for ; Fri, 1 Dec 2017 05:20:05 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=DJJTUI9NLxghaCDf6 CtK2lAvjm0tHA1jwmnFqnjmg2xHGiSDgJHNITL4gHRP0TxTk2MWg8XXprk/6ahOi tD9aw5tsg2bp07II9a57ax9V3wgDGcKZLt7RQ4l+d1VgTN7AdKARUzHwQHup1i6Z zsRZvPUchwgt0O3D7iRA3Mp7aw= 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 :subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=UdiroPozdpU+vWlOaaUczG8 lPFQ=; b=MeUu5WQ7ReWo2hdfNBLCLPTGPIzNy/Cm5JIaiuiZ3090XgXGzpUhf5F /4O25q410RWgEgJfgBQNKMO79qZJjmfaL6qTCfG/0SUpU7ly3CkhM7aPQUCRAdCl 6+S7QxGf8Mqjv/ISbqDk0Ttj17+uGYvBkLReUDNDOqJWSc6A7+jc= Received: (qmail 122522 invoked by alias); 30 Nov 2017 18:19:57 -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 122502 invoked by uid 89); 30 Nov 2017 18:19:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.9 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, KB_WAM_FROM_NAME_SINGLEWORD, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=tweaking, boo, H*RU:192.168.1.4, Hx-spam-relays-external:192.168.1.4 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 Nov 2017 18:19:55 +0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vAUIJmhA002056 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Nov 2017 18:19:49 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vAUIJlWX001027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Nov 2017 18:19:47 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vAUIJl1u014674; Thu, 30 Nov 2017 18:19:47 GMT Received: from [192.168.1.4] (/95.247.228.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Nov 2017 10:19:47 -0800 Subject: [C++ PING] Re: [C++ Patch, V2] PR 82593 ("Internal compiler error: in process_init_constructor_array, at cp/typeck2.c:1294") To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill , Nathan Sidwell References: <44bdbaa0-35f1-7f0c-85aa-b603939d016e@oracle.com> From: Paolo Carlini Message-ID: <44c93777-3841-e600-441d-0d616c357e0b@oracle.com> Date: Thu, 30 Nov 2017 19:19:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <44bdbaa0-35f1-7f0c-85aa-b603939d016e@oracle.com> X-IsSubscribed: yes Hi, On 17/11/2017 15:09, Paolo Carlini wrote: > Hi again, > > I managed to spend much more time on the issue and I'm starting a new > thread with a mature - IMHO - proposal: the big thing is the use of > the existing check_array_designated_initializer in > process_init_constructor_array,  which calls maybe_constant_value, as > we want, and covers all the ill-formed cases which I can imagine. I'm > also tweaking a bit the parser to check the return value of > require_potential_rvalue_constant_expression in order to avoid > redundant diagnostic in some cases. Also, a couple more testcases > beyond the bug report. I'm gently pinging this. I rebased it vs a very minor conflict due to Jakub's implementation of P0329R4. While I was at it, I'm also proposing a small tweak vs the previous version in the way check_array_designated_initializer is used: only if ce->index is non-null, more consistently with the current code. Or see the original post:     https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01481.html Thanks! Paolo. /////////////////////////// Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 255161) +++ cp/cp-tree.h (working copy) @@ -6190,6 +6190,8 @@ extern bool require_deduced_type (tree, tsubst_fl extern tree finish_case_label (location_t, tree, tree); extern tree cxx_maybe_build_cleanup (tree, tsubst_flags_t); +extern bool check_array_designated_initializer (constructor_elt *, + unsigned HOST_WIDE_INT); /* in decl2.c */ extern void record_mangling (tree, bool); Index: cp/decl.c =================================================================== --- cp/decl.c (revision 255161) +++ cp/decl.c (working copy) @@ -5249,7 +5249,7 @@ grok_reference_init (tree decl, tree type, tree in initializer. If it does, an error is issued. Returns true if CE is valid, i.e., does not have a designated initializer. */ -static bool +bool check_array_designated_initializer (constructor_elt *ce, unsigned HOST_WIDE_INT index) { Index: cp/parser.c =================================================================== --- cp/parser.c (revision 255161) +++ cp/parser.c (working copy) @@ -22218,8 +22218,10 @@ cp_parser_initializer_list (cp_parser* parser, boo if (!cp_parser_parse_definitely (parser)) designator = NULL_TREE; - else if (non_const) - require_potential_rvalue_constant_expression (designator); + else if (non_const + && (!require_potential_rvalue_constant_expression + (designator))) + designator = NULL_TREE; if (designator) /* Warn the user that they are using an extension. */ pedwarn (loc, OPT_Wpedantic, Index: cp/typeck2.c =================================================================== --- cp/typeck2.c (revision 255161) +++ cp/typeck2.c (working copy) @@ -1289,17 +1289,10 @@ process_init_constructor_array (tree type, tree in FOR_EACH_VEC_SAFE_ELT (v, i, ce) { - if (ce->index) - { - gcc_assert (TREE_CODE (ce->index) == INTEGER_CST); - if (compare_tree_int (ce->index, i) != 0) - { - ce->value = error_mark_node; - sorry ("non-trivial designated initializers not supported"); - } - } - else + if (!ce->index) ce->index = size_int (i); + else if (!check_array_designated_initializer (ce, i)) + ce->index = error_mark_node; gcc_assert (ce->value); ce->value = massage_init_elt (TREE_TYPE (type), ce->value, complain); Index: testsuite/g++.dg/cpp0x/desig2.C =================================================================== --- testsuite/g++.dg/cpp0x/desig2.C (nonexistent) +++ testsuite/g++.dg/cpp0x/desig2.C (working copy) @@ -0,0 +1,23 @@ +// PR c++/82593 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +enum { + INDEX1 = 0, + INDEX2 +}; + +class SomeClass { +public: + SomeClass(); +private: + struct { int field; } member[2]; +}; + +SomeClass::SomeClass() + : member({ + [INDEX1] = { .field = 0 }, + [INDEX2] = { .field = 1 } + }) +{ +} Index: testsuite/g++.dg/cpp0x/desig3.C =================================================================== --- testsuite/g++.dg/cpp0x/desig3.C (nonexistent) +++ testsuite/g++.dg/cpp0x/desig3.C (working copy) @@ -0,0 +1,21 @@ +// PR c++/82593 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +const int INDEX1 = 0; +const int INDEX2 = 1; + +class SomeClass { +public: + SomeClass(); +private: + struct { int field; } member[2]; +}; + +SomeClass::SomeClass() + : member({ + [INDEX1] = { .field = 0 }, + [INDEX2] = { .field = 1 } + }) +{ +} Index: testsuite/g++.dg/cpp0x/desig4.C =================================================================== --- testsuite/g++.dg/cpp0x/desig4.C (nonexistent) +++ testsuite/g++.dg/cpp0x/desig4.C (working copy) @@ -0,0 +1,21 @@ +// PR c++/82593 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +int INDEX1 = 0; +int INDEX2 = 1; + +class SomeClass { +public: + SomeClass(); +private: + struct { int field; } member[2]; +}; + +SomeClass::SomeClass() + : member({ + [INDEX1] = { .field = 0 }, // { dg-error "constant expression" } + [INDEX2] = { .field = 1 } // { dg-error "constant expression" } + }) +{ +}