From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix <memory> for -std=c++23 -ffreestanding [PR114866]
Date: Tue, 7 May 2024 14:48:18 +0100 [thread overview]
Message-ID: <20240507134836.3820823-1-jwakely@redhat.com> (raw)
Tested x86_64-linux. Pushed to trunk. gcc-14 backport to follow.
-- >8 --
std::shared_ptr isn't declared for freestanding, so guard uses of it
with #if _GLIBCXX_HOSTED in <bits/out_ptr.h>.
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 ++++++++++
| 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<typename _Smart, typename _Pointer, typename... _Args>
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<void>>::_Impl;
};
+#endif
using _Impl_t = _Impl<_Smart, _Pointer, _Args...>;
@@ -293,8 +297,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Smart, typename _Pointer, typename... _Args>
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<shared_ptr<T>, ...>
using _Out_ptr_t
= __conditional_t<__is_shared_ptr<_Smart>,
out_ptr_t<void*, void*>,
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;
};
--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 <memory> & out_ptr in freestanding
+#include <memory>
--
2.44.0
reply other threads:[~2024-05-07 13:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240507134836.3820823-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).