From patchwork Fri Jan 15 18:38:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1427270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=yjqa45DB; dkim-atps=neutral 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 (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DHVMB3hxQz9sRK for ; Sat, 16 Jan 2021 05:39:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1E1B3985817; Fri, 15 Jan 2021 18:38:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1E1B3985817 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610735939; bh=k3/cwgRVRPSvHSG/lot1LvZek+wgg1RpZsV/OEZaECU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yjqa45DBROwRXQ5Bnf0w5cIYLMe4OKmhoWfpUiBfwMczJFZ8XiLCgL4zmvbJdFBx3 BYEldQvoaeRlE9uA7JBRMHQpSYbUor9eXYZrDHtic4tNPjieLKpqgn2oZqXu3A0JmK vYfu/jH2UvANLFSPdP/5bb5bAogoTyM9K9NxEUlE= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id E21253857C63 for ; Fri, 15 Jan 2021 18:38:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E21253857C63 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-115-UjW8cBUMNgybIvnQUi7oug-1; Fri, 15 Jan 2021 13:38:55 -0500 X-MC-Unique: UjW8cBUMNgybIvnQUi7oug-1 Received: by mail-qk1-f199.google.com with SMTP id k126so8879614qkf.8 for ; Fri, 15 Jan 2021 10:38:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=k3/cwgRVRPSvHSG/lot1LvZek+wgg1RpZsV/OEZaECU=; b=N9/nAu5LD3b5vDH9Y8u/5uxrznbR12ko6l01G4H8Lg8A38WYUQiTL0TPTnIS9LFkkp gidf4G1EiN7X3b3sdTtEl1OkW7S9DimoV10SaFmvBKTMDvvugmFwNUIA15brMXU/a6UC BsYfnmjx7hDNaQ3n5wrlPVJHAscLWe1dWff9PS2InhQw+8bxMFuACsSIU10Mnz4NLJzK c48NV1Z4WB64KAq3QpmcPXXcsYWgx3v8f6UhHgrukcQ8QooKEc7J3cRvJBb0//2Vp7Pp dN5q/xt8gmcYmva8f8DnQZCQ2060K1tVi9kEK4K8vlenOeCfiXZdbHF5CieZz5GD7Qbl PLyg== X-Gm-Message-State: AOAM532EKOtnxcDp32gYey7tJq9aO36BJ3OmVRnkW9KHx6ZfmEDUiQRg wD4H51mPXRFtCxTieqWaNkbHatQg/JhI7/koZS3beysNLc8yQ7gM/X402uOOffK2xcW7eih0ZjW RwbpXB99xDD0d9cozWvyCDKn6o7kGuDcravjeeA9/LtT30Ka7UepNHwop7/gPOIwXMg== X-Received: by 2002:a05:620a:68e:: with SMTP id f14mr13622033qkh.460.1610735934221; Fri, 15 Jan 2021 10:38:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyuNjidpEhZj+lZi34ekeRW4y8wZTtLpT5AEUENTgVWgjg++eJBcXcp5ygaBNb55yCJAu0Vg== X-Received: by 2002:a05:620a:68e:: with SMTP id f14mr13621996qkh.460.1610735933849; Fri, 15 Jan 2021 10:38:53 -0800 (PST) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id x130sm5604464qkb.78.2021.01.15.10.38.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 10:38:52 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: Fix list-init of array of no-copy type [PR63707] Date: Fri, 15 Jan 2021 13:38:51 -0500 Message-Id: <20210115183851.2274892-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" build_vec_init_elt models initialization from some arbitrary object of the type, i.e. copy, but in the case of list-initialization we don't do a copy from the elements, we initialize them directly. Tested x86_64-pc-linux-gnu, applying to trunk. And 9/10, soon. gcc/cp/ChangeLog: PR c++/63707 * tree.c (build_vec_init_expr): Don't call build_vec_init_elt if we got a CONSTRUCTOR. gcc/testsuite/ChangeLog: PR c++/63707 * g++.dg/cpp0x/initlist-array13.C: New test. --- gcc/cp/tree.c | 10 +++++++++- gcc/testsuite/g++.dg/cpp0x/initlist-array13.C | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array13.C base-commit: c0194736b477aef3cf0d15ccd12c64572869cf3f diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3a9a86de34a..290e73bad83 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -787,7 +787,15 @@ build_vec_init_expr (tree type, tree init, tsubst_flags_t complain) { tree slot; bool value_init = false; - tree elt_init = build_vec_init_elt (type, init, complain); + tree elt_init; + if (init && TREE_CODE (init) == CONSTRUCTOR) + { + gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init)); + /* We built any needed constructor calls in digest_init. */ + elt_init = init; + } + else + elt_init = build_vec_init_elt (type, init, complain); if (init == void_type_node) { diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array13.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array13.C new file mode 100644 index 00000000000..92fe97164cd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array13.C @@ -0,0 +1,16 @@ +// PR c++/63707 +// { dg-do compile { target c++11 } } + +struct Child +{ + Child (int); + ~Child (); + Child (const Child &) = delete; +}; + +struct Parent +{ + Parent () : children {{5}, {7}} {} + + Child children[2]; +};