From patchwork Fri Feb 2 03:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1894273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H1s1t2qZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TR1Lt3BLKz1yhq for ; Fri, 2 Feb 2024 14:23:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E1803857C6B for ; Fri, 2 Feb 2024 03:23:16 +0000 (GMT) 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 9E6E63858C53 for ; Fri, 2 Feb 2024 03:22:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E6E63858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E6E63858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706844163; cv=none; b=Tg/rqJkbEdgk/xFH6PNxS1Brs7qfFY4Cu0d75c51yUNt+ElCCktc7YRl0sDRQZcYCH6kdElcU+leyCnYxz4hVVtQKPI9tX8beGG4B8T1YSSEQkvRFKR2kMGkI7/d78S+48oQRtmuxttJJFKwIN/TpcrHMF0R6AhU9gzmGNxQXYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706844163; c=relaxed/simple; bh=3ldsKi7bTHU55fX/wfUJ/FC6bmECJiNQm/0hfxv6l2s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=asP0692yxbmd+KSBR/APv5pwFhQoMjSsfurxRsQppSauET7GFm1JB3ZStSGfcPTEZeH64ytgOqaWFc+foSAe/3o98Jc+lMwE/kd+93ovBAfrqjnZ4f7KyRZt8GaTetjzlIW+S5ds/HLsM659zjkuJD0uGoIl0HydHwUghUyI4xM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706844152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+tJA2vwegZhVee+X7dAw9MnPHLjUMuQZneWDbHTiwyU=; b=H1s1t2qZ8ywYqme+LrVOYpOoD7frQMeNUNXNFZ8mzXjaX/eJOqLW/gmXktFYZbdKK0zCA0 4/x4NS7HhNSTTWWytup1oNFcvFG0HMAGgxIfn1JawWenHbWb+fw+lPUkFmvoplPvoHuTeV lIMDCbweDXWt5g34QOxDVB0OOwa+CQQ= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-lAyx3FeeMf2yc1z9m6nbrA-1; Thu, 01 Feb 2024 22:22:22 -0500 X-MC-Unique: lAyx3FeeMf2yc1z9m6nbrA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-42bf961faf4so11355681cf.0 for ; Thu, 01 Feb 2024 19:22:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706844141; x=1707448941; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+tJA2vwegZhVee+X7dAw9MnPHLjUMuQZneWDbHTiwyU=; b=VYmcJiaZuWMk9K1Z1xLgynf38FWMPQLPiMjSgk9MMOlpcoD9RZ3p+A2yII4ivJZh91 ssKu8OZi+9XrNSexhQkFQ3uAPyqComRBRTdNr/MEiTcxPJopOHTe6DGHdOrS7GBYVJzM cKz77PKaU12JvD377+vkHUaqXhbR13P8QOgxhWUWm2P7eLyhE7IAFEdLFmK3Qx4W4h/+ 7dDQ03o06GbEYH2GUi8T5wqmoRt6ToWealeDPny+rJTpQm8FVTS/Pjnvz3qxlVTUMbhZ H+OsU2egO4wzUn/Mm09L1tCDAqrqFyKmxNjwrMyp/h52mOcGtgyJ/GTNX9vCntrLOYN0 bDvg== X-Gm-Message-State: AOJu0YyNfKzL/WoLblyCKGx1YUuBLEJ2+kHbDJ5UY2FriHEIA5iWoIJO fvs3ozSr8EW/l2GNJvwcnO1W7yrl59180he6HPlXtUn5V1Gp0aadY6xjsfq7AhBKOnUyC2eKrAU c1yRXPytx04pVJGTgC4jmIX/60JzZoOmGTR79tos2BgqLTCiDr/eq7ZEvMwRSg14q6PhltuKn8p XiHa+1dmT+VZkhUoYCmdvmDs5ogGH9Ve23qDI= X-Received: by 2002:ac8:5cc7:0:b0:42a:ad8a:1e23 with SMTP id s7-20020ac85cc7000000b0042aad8a1e23mr8989889qta.62.1706844141280; Thu, 01 Feb 2024 19:22:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMg/Echl2k1wQ2o16ygaxqqCslgOP5DoKeuMfNsHvNZ8TlEFkoGx3uOVgT1N2WU9LlsDi3Bg== X-Received: by 2002:ac8:5cc7:0:b0:42a:ad8a:1e23 with SMTP id s7-20020ac85cc7000000b0042aad8a1e23mr8989875qta.62.1706844140906; Thu, 01 Feb 2024 19:22:20 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id i17-20020a05620a145100b00783268da8f0sm349608qkl.40.2024.02.01.19.22.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 19:22:20 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: no_unique_address and constexpr [PR112439] Date: Thu, 1 Feb 2024 22:22:18 -0500 Message-Id: <20240202032218.211819-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Here, because we don't build a CONSTRUCTOR for an empty base, we were wrongly marking the Foo CONSTRUCTOR as complete after initializing the Empty member. Fixed by checking empty_base here as well. PR c++/112439 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_store_expression): Check empty_base before marking a CONSTRUCTOR readonly. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/no_unique_address15.C: New test. --- gcc/cp/constexpr.cc | 1 + .../g++.dg/cpp2a/no_unique_address15.C | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C base-commit: e0701f8f7b6dcddb299eb5345e510cf9ea419150 prerequisite-patch-id: 710b09d2d596e61c5634974a1dca99c51506d903 diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 6350fe15408..2ebb1470dd5 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -6694,6 +6694,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, object. Make a note of this fact by marking the CONSTRUCTOR TREE_READONLY. */ if (TREE_CODE (t) == INIT_EXPR + && !empty_base && TREE_CODE (*valp) == CONSTRUCTOR && TYPE_READONLY (type)) { diff --git a/gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C b/gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C new file mode 100644 index 00000000000..3e7cf0838e1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C @@ -0,0 +1,19 @@ +// PR c++/112439 +// { dg-do compile { target c++14 } } + +struct Empty {}; + +class Foo { +public: + constexpr Foo(int x, Empty y, int z) : a(x), b(y) + { + c = z; + } + +private: + int a{}; + [[no_unique_address]] Empty b{}; + [[no_unique_address]] int c{}; +}; + +constexpr Foo r{1, {}, 3};