From patchwork Thu Jun 23 21:17:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1647355 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DpPk5nCg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LTY5D3ZC5z9s07 for ; Fri, 24 Jun 2022 07:18:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FED33850234 for ; Thu, 23 Jun 2022 21:18:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FED33850234 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656019102; bh=ZTWI0F5oVAttdyV7msral2/l/oi1ldoDxvqIVo1qhwo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DpPk5nCgR95UXlksyDKXNoC1diJM+ZzZa+6RjZO4zSy4OiySv+rzTIbWTAPZD0ebN yU+QocMq2OTdauSXs8oKaFwS4h6CBkPbAEUyTpen1LjAc9xeVbGH/UAbbR+2mLSAeh FHS4GfzsGMHX1sUVwx+bXJFFoXtu8YRHE+w6jHGw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 91938384F01A for ; Thu, 23 Jun 2022 21:17:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91938384F01A Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-368-SpU1eny4MoGRzeX70t6fXQ-1; Thu, 23 Jun 2022 17:17:10 -0400 X-MC-Unique: SpU1eny4MoGRzeX70t6fXQ-1 Received: by mail-qk1-f198.google.com with SMTP id i16-20020a05620a249000b006aedb25493cso445746qkn.15 for ; Thu, 23 Jun 2022 14:17:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZTWI0F5oVAttdyV7msral2/l/oi1ldoDxvqIVo1qhwo=; b=KUgFOuTjtN43pUdsG3uielEyY+ZTPTSWODvhL8qXBVJbpylqFYIcEE5epRoEiyPdT8 qJ7ztpZOYpnHfIS9o+CGL6RJTb33LGop6hxCCDnVa8HsbebJuBla/Kg3M92RMjjIv5Tl ZxGH2Hwqd5lyzYEQy5/mBNshEFL4lQ2S22ucZajT4Z2INS2ILqgwVhjLpxoDwDzjQmqJ t6HDChH21Nd6nSc+R0AMD4XTKyCc1Vc3Wg59Eqvqtj+fUg9nvyVsh6kYogQy+nYLYFKI jyLNDN6uXwqjKPg2V9W0gctaL9wBP2UHpHRToaqLOLO1uo5Z9uvBRZHtPG2kwxJosK3k QDYQ== X-Gm-Message-State: AJIora8FALgR8CTy7/NBIkklsBsjbv8n97O4HQhnYu6hXSni/YvlCqaq hZeemcMVTypd5F6O8/OSshbJCKGqSDeCnT/BLo7Zjd/KVap27iulGlPDgwyTW0TZWxmPHLDkYrS sRWxUrooF/WbzS35w7cc6TSpKOq0Idh/CmZu9v+xMtVFIwsZQv5B1+KVib9cpKnMMHA== X-Received: by 2002:a05:620a:bc3:b0:6a7:9e01:95ac with SMTP id s3-20020a05620a0bc300b006a79e0195acmr8140966qki.91.1656019029369; Thu, 23 Jun 2022 14:17:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+a/TrLBGqVH77KgcYtb6ri0lmWloYtrkgFnMU7VpGwlZEETV/Bukfm3M+Xpnk0zi6O6pPTw== X-Received: by 2002:a05:620a:bc3:b0:6a7:9e01:95ac with SMTP id s3-20020a05620a0bc300b006a79e0195acmr8140935qki.91.1656019028912; Thu, 23 Jun 2022 14:17:08 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o30-20020a05620a0d5e00b006aee8a5fa4bsm445999qkl.43.2022.06.23.14.17.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 14:17:08 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: designated init cleanup [PR105925] Date: Thu, 23 Jun 2022 17:17:07 -0400 Message-Id: <20220623211707.182601-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220623211627.182384-1-jason@redhat.com> References: <20220623211627.182384-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" build_aggr_conv expects to run after reshape_init, which will usually have filled out all the CONSTRUCTOR indexes; there's no reason to limit using those to the case where the user gave an explicit designator. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/105925 gcc/cp/ChangeLog: * call.cc (build_aggr_conv): Don't depend on CONSTRUCTOR_IS_DESIGNATED_INIT. --- gcc/cp/call.cc | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) base-commit: d610ae121e8ecd738de4dc01e6ac11ecf7c2327e diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 4710c3777c5..f1dd8377628 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -969,7 +969,8 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain) tree empty_ctor = NULL_TREE; hash_set pset; - /* We already called reshape_init in implicit_conversion. */ + /* We already called reshape_init in implicit_conversion, but it might not + have done anything in the case of parenthesized aggr init. */ /* The conversions within the init-list aren't affected by the enclosing context; they're always simple copy-initialization. */ @@ -979,49 +980,48 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain) to corresponding TREE_TYPE (ce->index) and mark those FIELD_DECLs as visited. In the following loop then ignore already visited FIELD_DECLs. */ - if (CONSTRUCTOR_IS_DESIGNATED_INIT (ctor)) + tree idx, val; + FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val) { - tree idx, val; - FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, val) + if (!idx) + break; + + gcc_checking_assert (TREE_CODE (idx) == FIELD_DECL); + + tree ftype = TREE_TYPE (idx); + bool ok; + + if (TREE_CODE (ftype) == ARRAY_TYPE) + ok = can_convert_array (ftype, val, flags, complain); + else + ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags, + complain); + + if (!ok) + return NULL; + + /* For unions, there should be just one initializer. */ + if (TREE_CODE (type) == UNION_TYPE) { - if (idx && TREE_CODE (idx) == FIELD_DECL) - { - tree ftype = TREE_TYPE (idx); - bool ok; - - if (TREE_CODE (ftype) == ARRAY_TYPE) - ok = can_convert_array (ftype, val, flags, complain); - else - ok = can_convert_arg (ftype, TREE_TYPE (val), val, flags, - complain); - - if (!ok) - return NULL; - /* For unions, there should be just one initializer. */ - if (TREE_CODE (type) == UNION_TYPE) - { - field = NULL_TREE; - i = 1; - break; - } - pset.add (idx); - } - else - return NULL; + field = NULL_TREE; + i = 1; + break; } + pset.add (idx); } for (; field; field = next_aggregate_field (DECL_CHAIN (field))) { tree ftype = TREE_TYPE (field); - tree val; bool ok; if (!pset.is_empty () && field_in_pset (pset, field)) continue; if (i < CONSTRUCTOR_NELTS (ctor)) { - val = CONSTRUCTOR_ELT (ctor, i)->value; + constructor_elt *ce = CONSTRUCTOR_ELT (ctor, i); + gcc_checking_assert (!ce->index); + val = ce->value; ++i; } else if (DECL_INITIAL (field))