From patchwork Thu May 2 11:26:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1930599 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=X6CVd9Ry; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVWwy4hfxz1ydX for ; Thu, 2 May 2024 21:31:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B76923865479 for ; Thu, 2 May 2024 11:31:44 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id DF517384AB4B for ; Thu, 2 May 2024 11:31:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF517384AB4B 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 DF517384AB4B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714649481; cv=none; b=SM+3iN47RLouZqavYJZTPkQo7UUCtrwVHF9SSr4HDfYPAMgYRqa4zasRtD3vh1qWXbF72PRlHwpnarjLdp0yxESlKU7aPYc1dwHy3VdauEFYeRty+8yrIIXV/HGvAwBGxll0wicW3o01lL5EMiILaNYa+htMYFGwcHQFaPs/CtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714649481; c=relaxed/simple; bh=afZe2dmt6Kf7iRb+4cMymHiauGtfPxKBykf/Iye/7/k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=e/ZWb9WBa7fzebn+4Evd0wu8/eVarAjY+gkHdqVOv05YvhvN0CquPEwJMfDJy+5FICb6uO8e0kGTuNTYb8oLpVsdBEl4MQ7mTrDAv3Fr4OwmEfgr4rSJteYFh5ACWpqUXTHjsusVoU+6l00csYeqVkqJaBCDFfdoecOOGZRHde0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714649479; 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=iQFkbwjboBObc6KKxQ2iG5L7CVwlzRNgqQhVH21TZWU=; b=X6CVd9RyX223YePCA0S/+dixp7G0WLSEzZF3JBsd3zkZeRQ4dMN+62NP9lhCQwh6pXzXIz uYOAujxB+Vb7RmNcZS6SA4edXzoW17Ep53M2zczAGiRAWZOCMwTEU9JFndHQQtWqAOpTW1 rf+yr3bl5ELkkB3wMXP80zSmyR4K7K4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-mzVRLvx0Mqy2pTLHFBR4NA-1; Thu, 02 May 2024 07:31:18 -0400 X-MC-Unique: mzVRLvx0Mqy2pTLHFBR4NA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A2D680B3DD; Thu, 2 May 2024 11:31:18 +0000 (UTC) Received: from localhost (unknown [10.42.28.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDCFB47B; Thu, 2 May 2024 11:31:17 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Fix for -std=c++23 -ffreestanding [PR114866] Date: Thu, 2 May 2024 12:26:12 +0100 Message-ID: <20240502113117.3346412-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX 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-linux. It would also be possible to fix this with: #if ! _GLIBCXX_HOSTED template inline constexpr __is_shared_ptr = false; #endif But we would still need to guard the partial specializations that use shared_ptr and __shared_ptr. It seemed cleaner to just guard all uses of anything related to shared_ptr so it all goes away for freestanding. While working on this I noticed that when I added __is_shared_ptr I made it 'static constexpr' for some reason, rather than 'inline constexpr'. I'll change that separately. -- >8 -- std::shared_ptr isn't declared for freestanding, so guard uses of it with #if _GLIBCXX_HOSTED in . libstdc++-v3/ChangeLog: PR libstdc++/114866 * include/bits/out_ptr.h [!_GLIBCXX_HOSTED]: Don't refer to shared_ptr, __shared_ptr or __is_shred_ptr. * testsuite/20_util/headers/memory/114866.cc: New test. --- libstdc++-v3/include/bits/out_ptr.h | 10 ++++++++++ .../testsuite/20_util/headers/memory/114866.cc | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/headers/memory/114866.cc diff --git a/libstdc++-v3/include/bits/out_ptr.h b/libstdc++-v3/include/bits/out_ptr.h index aeeb6640441..d74c9f52d3b 100644 --- a/libstdc++-v3/include/bits/out_ptr.h +++ b/libstdc++-v3/include/bits/out_ptr.h @@ -54,9 +54,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class out_ptr_t { +#if _GLIBCXX_HOSTED static_assert(!__is_shared_ptr<_Smart> || sizeof...(_Args) != 0, "a deleter must be used when adapting std::shared_ptr " "with std::out_ptr"); +#endif public: explicit @@ -216,6 +218,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [[no_unique_address]] _Del2 _M_del; }; +#if _GLIBCXX_HOSTED // Partial specialization for std::shared_ptr. // This specialization gives direct access to the private member // of the shared_ptr, avoiding the overhead of storing a separate @@ -274,6 +277,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { using _Impl<_Smart, _Pointer, _Del, allocator>::_Impl; }; +#endif using _Impl_t = _Impl<_Smart, _Pointer, _Args...>; @@ -293,8 +297,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class inout_ptr_t { +#if _GLIBCXX_HOSTED static_assert(!__is_shared_ptr<_Smart>, "std::inout_ptr can not be used to wrap std::shared_ptr"); +#endif public: explicit @@ -320,11 +326,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } private: +#if _GLIBCXX_HOSTED // Avoid an invalid instantiation of out_ptr_t, ...> using _Out_ptr_t = __conditional_t<__is_shared_ptr<_Smart>, out_ptr_t, out_ptr_t<_Smart, _Pointer, _Args...>>; +#else + using _Out_ptr_t = out_ptr_t<_Smart, _Pointer, _Args...>; +#endif using _Impl_t = typename _Out_ptr_t::_Impl_t; _Impl_t _M_impl; }; diff --git a/libstdc++-v3/testsuite/20_util/headers/memory/114866.cc b/libstdc++-v3/testsuite/20_util/headers/memory/114866.cc new file mode 100644 index 00000000000..7cf6be0539d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/headers/memory/114866.cc @@ -0,0 +1,4 @@ +// { dg-options "-ffreestanding" } +// { dg-do compile } +// PR libstdc++/114866 & out_ptr in freestanding +#include