From patchwork Thu Jun 2 19:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1638429 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=IGfxiMkH; 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 4LDbMp2QPNz9s0w for ; Fri, 3 Jun 2022 05:16:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A174386EC0E for ; Thu, 2 Jun 2022 19:16:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A174386EC0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654197362; bh=NOG2thrkD2fcD3Nr8uHwmS6jSHmGLwNKwv7aoaCiwzQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IGfxiMkHMdZw6OaoOOPUKUYZgk7JnGf2ZVq8ubEh2b5abauUYxzZipU1KdZMRTdZ5 YHmFin8zsDG+DHvwQIaG4Hny8PVGeGCBnGgD/sT9AyBEle8B2MKy3YWOaxJe8Y38aY KeE9hkZSAjJXpisxNH+ixFBIe47MwBIpVsXBEvhg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id E1DF4382FC00 for ; Thu, 2 Jun 2022 19:15:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1DF4382FC00 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647--rgpHxjyM9Ww2zQdhLxQwA-1; Thu, 02 Jun 2022 15:15:41 -0400 X-MC-Unique: -rgpHxjyM9Ww2zQdhLxQwA-1 Received: by mail-qt1-f199.google.com with SMTP id u2-20020ac80502000000b002f94701339eso4338902qtg.13 for ; Thu, 02 Jun 2022 12:15:40 -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:mime-version :content-transfer-encoding; bh=NOG2thrkD2fcD3Nr8uHwmS6jSHmGLwNKwv7aoaCiwzQ=; b=co22KoWBCWmXZnOYUN4RxMGPoWVrhgWd8MYmrIVoGZzJtmj6cQzLPEeaKQVd7ecntn CNc4VGN0VMmxx1tNRpeXHnXnG3CjCQPFqdpZxFYIy2W0S4Ctsm7soHhU606yc/e68IMA 4AP5+MzCWmJrvwavona2U0z8t7wKszbixA2wzFnIwtGN6xp3eGj5kgOV7+dwgKzI7qPe dfD9+oUsqIaYofyIO32mF9uAVNhY1H/L2TfabevEYG3HasV31jExIFwqMPpEdfSm8uah MbufhyX3Pnx9wcv4UhAq+jDu+Oayvw7e05yMFC10YwatwNUBnYrCaUhcBsIv8gWZwqdr tkbQ== X-Gm-Message-State: AOAM530k3Jgh+Vawemo+tku6Ez8/34BpOWMNyclEPh96cXGtwuml7DjO Q00OkG9dHqSdlVFX/jZechuRYdutu3H7LDvOUvXYscSrRsYhxWBl3fnnh7gsvxtiJQKWkCIXpAp b57p4URkr4f8kePY+pn1vLiP4f0J26EHJa8OdBsYItL2nsSt/Qk1F2QHeqpspOfK68w== X-Received: by 2002:a05:622a:13:b0:301:6d0d:c731 with SMTP id x19-20020a05622a001300b003016d0dc731mr4867578qtw.43.1654197340049; Thu, 02 Jun 2022 12:15:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4rgKUsikCJfSatcWG4D1aoFL8HpydoehyYJJxdpzrEm35F+RxgsWjh+2YHGSSDID2XnNCsA== X-Received: by 2002:a05:622a:13:b0:301:6d0d:c731 with SMTP id x19-20020a05622a001300b003016d0dc731mr4867562qtw.43.1654197339642; Thu, 02 Jun 2022 12:15:39 -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 t16-20020ac85890000000b002f39b99f685sm3693815qta.31.2022.06.02.12.15.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 12:15:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: constexpr empty aggr [PR105795] Date: Thu, 2 Jun 2022 15:15:37 -0400 Message-Id: <20220602191537.1918510-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.1 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_NONE, 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" In this testcase, leaving ctx->ctor pointing to the enclosing object meant that evaluating the initializer for the subobject clobbered previous initializers for the enclosing object. So do update ctx->ctor, just don't add it to the enclosing object ctor. Tested x86_64-pc-linux-gnu, applying to trunk and 12. PR c++/105795 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_bare_aggregate): Always call init_subob_ctx. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-aggr-base1.C: New test. --- gcc/cp/constexpr.cc | 7 ++--- .../g++.dg/cpp1z/constexpr-aggr-base1.C | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-aggr-base1.C base-commit: 37e4e7f77d8f7b7e911bf611a0f8edbc3a850c7a diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 45208478c3f..021eaa34920 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -4777,12 +4777,9 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, tree orig_value = value; /* Like in cxx_eval_store_expression, omit entries for empty fields. */ bool no_slot = TREE_CODE (type) == RECORD_TYPE && is_empty_field (index); - if (no_slot) - new_ctx = *ctx; - else - init_subob_ctx (ctx, new_ctx, index, value); + init_subob_ctx (ctx, new_ctx, index, value); int pos_hint = -1; - if (new_ctx.ctor != ctx->ctor) + if (new_ctx.ctor != ctx->ctor && !no_slot) { /* If we built a new CONSTRUCTOR, attach it now so that other initializers can refer to it. */ diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-aggr-base1.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-aggr-base1.C new file mode 100644 index 00000000000..06acb4a9f78 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-aggr-base1.C @@ -0,0 +1,27 @@ +// PR c++/105795 +// { dg-do compile { target c++17 } } + +struct empty +{}; + +template +struct tuple_holder +{ + [[no_unique_address]] T value; +}; + +struct tuple : tuple_holder, tuple_holder +{}; + +constexpr auto make_tuple(int&& i, empty&& e) +{ + return tuple{i, e}; +} + +constexpr int foo() +{ + auto tuple = make_tuple(1, empty{}); + return static_cast&>(tuple).value; +} + +static_assert (foo() == 1);