From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 3C7693858410; Tue, 7 May 2024 13:48:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C7693858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715089699; bh=33V3RdBhy0Y3xntMQuTgJ0Fkt472dLR0YoNAi/5SK1E=; h=From:To:Subject:Date:From; b=nYUWIAZfq/xNk6vE1sN/PGzbnCJCdESsjyz8W5zpAqozvVETfIxl7YBITqOmoxTXk 5NZhQd5zNsZM0aOKJSjdvNBPcVNOlC/Lnggi42eZIt0SfS++uwsO22rfhxxRZwd7lO AA8IzEbsEObre3/YnJScLOZNcq9uGLsBgJ0QLUtw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r15-284] libstdc++: Fix for -std=c++23 -ffreestanding [PR114866] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 6709e35457a30b2184fa8337aa4abdd2c0edaeb3 X-Git-Newrev: 9927059bb88e966e0a45f09e4fd1193f93df708f Message-Id: <20240507134819.3C7693858410@sourceware.org> Date: Tue, 7 May 2024 13:48:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9927059bb88e966e0a45f09e4fd1193f93df708f commit r15-284-g9927059bb88e966e0a45f09e4fd1193f93df708f Author: Jonathan Wakely Date: Thu May 2 12:14:52 2024 +0100 libstdc++: Fix for -std=c++23 -ffreestanding [PR114866] 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. Diff: --- libstdc++-v3/include/bits/out_ptr.h | 10 ++++++++++ libstdc++-v3/testsuite/20_util/headers/memory/114866.cc | 4 ++++ 2 files changed, 14 insertions(+) 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