From patchwork Mon Nov 15 23:50:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1555559 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=wCep82Ef; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HtQv64Vd8z9sR4 for ; Tue, 16 Nov 2021 10:51:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A7673857C75 for ; Mon, 15 Nov 2021 23:51:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A7673857C75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637020269; bh=EdsLP1TYmFqfy0EApa5s0qPGVE23paSy3m+Kos3aaKc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wCep82EfPCqt4CToPZW8gttW9/z+FnAuw1nAAqFLEWeobyX67CKx9iaQe/Np/i4HW qXILmlSvMHmgQM67xYnfqcA0jbOT1WNl5sgr1Bo41njnyj+X4FgwoCX0yc0NZyPB6C TbAIKQL21TdSE2n+oZRRpS1kyf9jBsA/3omZr9Yg= 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 489D03857C42 for ; Mon, 15 Nov 2021 23:50:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 489D03857C42 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-miB0GK-tN4qCJbRmEAEVHw-1; Mon, 15 Nov 2021 18:50:06 -0500 X-MC-Unique: miB0GK-tN4qCJbRmEAEVHw-1 Received: by mail-qt1-f197.google.com with SMTP id o12-20020a05622a008c00b002aff5552c89so13887968qtw.23 for ; Mon, 15 Nov 2021 15:50:06 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=EdsLP1TYmFqfy0EApa5s0qPGVE23paSy3m+Kos3aaKc=; b=AS66Q8DFmZp+kwI2H49+rRw0AwwocPJIQ1Vr3xEFyNZnXDDe0hkzlv+XvIpwKVfEL+ rsr79iZrlSgbYTj0Y20OmTkxzwlhS6TEHukSKjkyhUNk574pic9AKvm0Dyv4QZ83zrP8 BQa684kjjui40VpRUA7j4BwgUgmebr04b0u2EL7p3qWX22rbX2lxxGxBiu99WeNyDm3U zGxyrwhhX4hgCAvBZXN40cQgvIxGT+uqc80WAfk3YodhP7uo7PTsyNyyev29VQ9FpjDV RkiYe96WE/qsr8MoamodrqQcIAJrrArdverLrO5ER/iU3JsYEyvyZqB5MBFUDEBSm6zJ Dxag== X-Gm-Message-State: AOAM5303qTsCTIZoAiQ5hW4Du2sZIMV1lw1IrfU6cM0Fc7JbrZNEBoaP FsQj/2ezrQ6JMpzYuhdWya/hcKFi2RmWJBOgZpa/acL3parxflRlucV5QlDlUlTsgpjGAIiXuuE zN285o4VYaTstxFzGYiBJU1/flWH2XeNYEgYSaBx7LIRgTv+HF3R3JJIcPFLDc7bMJQ== X-Received: by 2002:ae9:ef11:: with SMTP id d17mr2393258qkg.347.1637020205999; Mon, 15 Nov 2021 15:50:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyp/TTanMpFB1OETSjk/08Liaec1o36278yHqvOHhnkljSuFBVs9pOQ9W6af8OeuXa7iowm9Q== X-Received: by 2002:ae9:ef11:: with SMTP id d17mr2393217qkg.347.1637020205495; Mon, 15 Nov 2021 15:50:05 -0800 (PST) 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 z16sm7358425qki.25.2021.11.15.15.50.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 15:50:04 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: split_nonconstant_init and flexarrays Date: Mon, 15 Nov 2021 18:50:02 -0500 Message-Id: <20211115235002.3492264-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=-13.4 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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" split_nonconstant_init was doing the wrong thing for both the initialization and cleanup here; we know the size from the initializer, and we can pass it along. This doesn't make the testcase work, since the y destructor is still broken, but it removes the wrong error for the aggregate initialization. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * typeck2.c (split_nonconstant_init_1): Handle flexarrays better. gcc/testsuite/ChangeLog: * g++.dg/ext/flexary37.C: Remove expected error. --- gcc/cp/typeck2.c | 9 +++++++++ gcc/testsuite/g++.dg/ext/flexary37.C | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) base-commit: 323026c7dfe23e1093e80f7db5f4851d1a867b62 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index c01f2f8ced4..e98fbf7f5fa 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -484,6 +484,15 @@ split_nonconstant_init_1 (tree dest, tree init, bool nested) && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) || vla_type_p (type)) { + if (!TYPE_DOMAIN (type) + && TREE_CODE (init) == CONSTRUCTOR + && CONSTRUCTOR_NELTS (init)) + { + /* Flexible array. */ + cp_complete_array_type (&type, init, /*default*/true); + dest = build1 (VIEW_CONVERT_EXPR, type, dest); + } + /* For an array, we only need/want a single cleanup region rather than one per element. */ tree code = build_vec_init (dest, NULL_TREE, init, false, 1, diff --git a/gcc/testsuite/g++.dg/ext/flexary37.C b/gcc/testsuite/g++.dg/ext/flexary37.C index ceb5053de2e..5cd48c1f773 100644 --- a/gcc/testsuite/g++.dg/ext/flexary37.C +++ b/gcc/testsuite/g++.dg/ext/flexary37.C @@ -12,4 +12,4 @@ public: struct y { // { dg-error "unknown array size in delete" } int a; C b[]; -} y = { 1, { { 2, 3 } } }; // { dg-error "unknown array size in delete" } +} y = { 1, { { 2, 3 } } };