From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Support printing volatile pointers (P1147R1)
Date: Tue, 5 Oct 2021 09:38:23 +0100 [thread overview]
Message-ID: <YVwO/8GxaXEVx4rO@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 378 bytes --]
To avoid needing to export a new symbol from the library (for now) the
new member function uses __attribute__((always_inline)).
libstdc++-v3/ChangeLog:
* include/std/ostream (operator<<(const volatile void*)):
Add new overload, as per P1147R1.
* testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc:
New test.
Tested powerpc64le-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1746 bytes --]
commit 96955a82f0e1624a20ea2c9953d76a20ea433c24
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Oct 4 15:22:00 2021
libstdc++: Support printing volatile pointers (P1147R1)
To avoid needing to export a new symbol from the library (for now) the
new member function uses __attribute__((always_inline)).
libstdc++-v3/ChangeLog:
* include/std/ostream (operator<<(const volatile void*)):
Add new overload, as per P1147R1.
* testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc:
New test.
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index ddb33feb12f..7d39c5706d5 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -251,6 +251,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return *this << "nullptr"; }
#endif
+#if __cplusplus > 202002L
+ __attribute__((__always_inline__))
+ __ostream_type&
+ operator<<(const volatile void* __p)
+ { return _M_insert(const_cast<const void*>(__p)); }
+#endif
+
/**
* @brief Extracting from another streambuf.
* @param __sb A pointer to a streambuf
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc
new file mode 100644
index 00000000000..1b1a9434a95
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc
@@ -0,0 +1,11 @@
+// { dg-options "-std=gnu++23 -fno-inline" }
+// { dg-do link { target c++23 } }
+
+#include <iostream>
+
+int main()
+{
+ int i = 0;
+ volatile void* p = &i;
+ std::cout << p << std::endl;
+}
next reply other threads:[~2021-10-05 8:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 8:38 Jonathan Wakely [this message]
2021-10-05 9:28 ` Daniel Krügler
2021-10-05 15:07 ` Jonathan Wakely
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=YVwO/8GxaXEVx4rO@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).