diff --git a/stl/inc/ostream b/stl/inc/ostream index cf8721cdc64..23049b5d156 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -454,7 +454,14 @@ public: return *this; } -#if _HAS_CXX17 // LWG-2221 "No formatted output operator for nullptr" +#if _HAS_CXX23 + template // TRANSITION, ABI + basic_ostream& operator<<(const volatile void* _Val) { + return *this << const_cast(_Val); + } +#endif // _HAS_CXX23 + +#if _HAS_CXX17 template // TRANSITION, ABI basic_ostream& operator<<(nullptr_t) { // insert a null pointer return *this << "nullptr"; diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index b143b684dfe..9aef059f37a 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -275,6 +275,7 @@ // P0943R6 Supporting C Atomics In C++ // P1048R1 is_scoped_enum // P1132R7 out_ptr(), inout_ptr() +// P1147R1 Printing volatile Pointers // P1272R4 byteswap() // P1425R4 Iterator Pair Constructors For stack And queue // P1659R3 ranges::starts_with, ranges::ends_with diff --git a/tests/std/test.lst b/tests/std/test.lst index d16e02732c3..8495b2774fb 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -433,6 +433,7 @@ tests\P1135R6_atomic_wait_vista tests\P1135R6_barrier tests\P1135R6_latch tests\P1135R6_semaphore +tests\P1147R1_printing_volatile_pointers tests\P1165R1_consistently_propagating_stateful_allocators tests\P1208R6_source_location tests\P1272R4_byteswap diff --git a/tests/std/tests/P1147R1_printing_volatile_pointers/env.lst b/tests/std/tests/P1147R1_printing_volatile_pointers/env.lst new file mode 100644 index 00000000000..642f530ffad --- /dev/null +++ b/tests/std/tests/P1147R1_printing_volatile_pointers/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_latest_matrix.lst diff --git a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp new file mode 100644 index 00000000000..c8820f5cc7e --- /dev/null +++ b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include + +using namespace std; + +template +string getTextValue(T* ptr) { + ostringstream out; + out << ptr; + return out.str(); +} + +void test(int value) { + int* p0 = &value; + volatile int* p1 = p0; + + const string expected = getTextValue(p0); + const string actual = getTextValue(p1); + + assert(expected == actual); +} + +int main() { + test(42); +}