From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" 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-List-Received-Date: Mon, 15 Nov 2021 23:50:09 -0000 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(-) 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 } } }; base-commit: 323026c7dfe23e1093e80f7db5f4851d1a867b62 -- 2.27.0