aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-10-04 15:22:00 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-10-05 09:35:47 +0100
commit96955a82f0e1624a20ea2c9953d76a20ea433c24 (patch)
tree2dafacc6ed0021b7143504aaba470c840e73e94b
parent9e136807c5b5476ed02a2a40a14fe0df3c0f4f18 (diff)
downloadgcc-96955a82f0e1624a20ea2c9953d76a20ea433c24.zip
gcc-96955a82f0e1624a20ea2c9953d76a20ea433c24.tar.gz
gcc-96955a82f0e1624a20ea2c9953d76a20ea433c24.tar.bz2
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.
-rw-r--r--libstdc++-v3/include/std/ostream7
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc11
2 files changed, 18 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index ddb33fe..7d39c57 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 0000000..1b1a943
--- /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;
+}