From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id C66843857C71; Wed, 24 Nov 2021 11:51:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C66843857C71 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 r11-9294] libstdc++: Support printing volatile pointers (P1147R1) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 88d481c9ee1e6a24dc11ab56d8688308e0211855 X-Git-Newrev: 58752dd237e95d06c080c7669f039a2c7cfac938 Message-Id: <20211124115143.C66843857C71@sourceware.org> Date: Wed, 24 Nov 2021 11:51:43 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2021 11:51:43 -0000 https://gcc.gnu.org/g:58752dd237e95d06c080c7669f039a2c7cfac938 commit r11-9294-g58752dd237e95d06c080c7669f039a2c7cfac938 Author: Jonathan Wakely Date: Mon Oct 4 15:22:00 2021 +0100 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. (cherry picked from commit 96955a82f0e1624a20ea2c9953d76a20ea433c24) Diff: --- libstdc++-v3/include/std/ostream | 7 +++++++ .../27_io/basic_ostream/inserters_other/char/volatile_ptr.cc | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index 981697324c9..722d4ff61b5 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(__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 + +int main() +{ + int i = 0; + volatile void* p = &i; + std::cout << p << std::endl; +}