From 4b798253e71cee0c52de1234442deac752e773a9 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 6 Oct 2021 22:37:21 +0700 Subject: [PATCH 1/9] Implemented P1147R1 "Printing volatile Pointers" --- stl/inc/ostream | 7 ++++ stl/inc/yvals_core.h | 1 + tests/std/test.lst | 1 + .../env.lst | 4 +++ .../test.cpp | 34 +++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 tests/std/tests/P1147R1_printing_volotile_pointers/env.lst create mode 100644 tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp diff --git a/stl/inc/ostream b/stl/inc/ostream index cf8721cdc64..a5e41feccf8 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -454,6 +454,13 @@ public: return *this; } +#if _HAS_CXX23 // P1147R1 "Printing volatile Pointers" + template // TRANSITION, ABI + basic_ostream& operator<<(const volatile void* _Val) { + return *this << (const_cast(_Val)); + } +#endif // _HAS_CXX23 + #if _HAS_CXX17 // LWG-2221 "No formatted output operator for nullptr" template // TRANSITION, ABI basic_ostream& operator<<(nullptr_t) { // insert a null pointer diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index a50241bf19b..28e81720fe8 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 // P1425R4 Iterator Pair Constructors For stack And queue // P1679R3 contains() For basic_string/basic_string_view // P1682R3 to_underlying() For Enumerations diff --git a/tests/std/test.lst b/tests/std/test.lst index f3f611f9b5b..1ebd00df77d 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -432,6 +432,7 @@ tests\P1135R6_atomic_wait_vista tests\P1135R6_barrier tests\P1135R6_latch tests\P1135R6_semaphore +tests\P1147R1_printing_volotile_pointers tests\P1165R1_consistently_propagating_stateful_allocators tests\P1208R6_source_location tests\P1423R3_char8_t_remediation diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst new file mode 100644 index 00000000000..18e2d7c71ec --- /dev/null +++ b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_latest_matrix.lst diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp new file mode 100644 index 00000000000..2e5c6bdc839 --- /dev/null +++ b/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include + +using namespace std; + +std::string getExpected(int* ptr) { + ostringstream out; + out << ptr; + return out.str(); +} + +std::string getActual(volatile int* ptr) { + ostringstream out; + out << ptr; + return out.str(); +} + +void test(size_t value) { + int* p0 = reinterpret_cast(value); + volatile int* p1 = reinterpret_cast(p0); + + string expected = getExpected(p0); + string actual = getActual(p1); + + assert(expected == actual); +} + +int main() { + test(0xdeadbeef); +} From c9ad43907f331db27623fd26a8e6334898f7806b Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 6 Oct 2021 22:42:44 +0700 Subject: [PATCH 2/9] add const and include --- tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp index 2e5c6bdc839..bd7ce84cedf 100644 --- a/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp +++ b/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -#include +#include #include using namespace std; @@ -23,8 +23,8 @@ void test(size_t value) { int* p0 = reinterpret_cast(value); volatile int* p1 = reinterpret_cast(p0); - string expected = getExpected(p0); - string actual = getActual(p1); + const string expected = getExpected(p0); + const string actual = getActual(p1); assert(expected == actual); } From be5d8e4dfe68c63c69b40ffad4803e7e03922376 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 6 Oct 2021 22:52:24 +0700 Subject: [PATCH 3/9] wrong matrix --- tests/std/tests/P1147R1_printing_volotile_pointers/env.lst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst index 18e2d7c71ec..642f530ffad 100644 --- a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst +++ b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\concepts_latest_matrix.lst +RUNALL_INCLUDE ..\usual_latest_matrix.lst From 5b75b76dcf6804929291d2153c79ecba830dbd22 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 6 Oct 2021 23:23:56 +0700 Subject: [PATCH 4/9] Implement P1147R1 as Defect Report --- stl/inc/ostream | 4 ++-- stl/inc/yvals_core.h | 2 +- tests/std/tests/P1147R1_printing_volotile_pointers/env.lst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index a5e41feccf8..44807718793 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -454,12 +454,12 @@ public: return *this; } -#if _HAS_CXX23 // P1147R1 "Printing volatile Pointers" +#if _HAS_CXX20 // P1147R1 "Printing volatile Pointers" template // TRANSITION, ABI basic_ostream& operator<<(const volatile void* _Val) { return *this << (const_cast(_Val)); } -#endif // _HAS_CXX23 +#endif // _HAS_CXX20 #if _HAS_CXX17 // LWG-2221 "No formatted output operator for nullptr" template // TRANSITION, ABI diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 28e81720fe8..d63e72f1bbf 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -207,6 +207,7 @@ // P1115R3 erase()/erase_if() Return size_type // P1123R0 Atomic Compare-And-Exchange With Padding Bits For atomic_ref // P1135R6 The C++20 Synchronization Library +// P1147R1 Printing volatile Pointers // P1207R4 Movability Of Single-Pass Iterators // P1208R6 // P1209R0 erase_if(), erase() @@ -275,7 +276,6 @@ // P0943R6 Supporting C Atomics In C++ // P1048R1 is_scoped_enum // P1132R7 out_ptr(), inout_ptr() -// P1147R1 Printing volatile Pointers // P1425R4 Iterator Pair Constructors For stack And queue // P1679R3 contains() For basic_string/basic_string_view // P1682R3 to_underlying() For Enumerations diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst index 642f530ffad..351a8293d9d 100644 --- a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst +++ b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\usual_latest_matrix.lst +RUNALL_INCLUDE ..\usual_20_matrix.lst From a236d5121b9eee3dc608e42dba4cb037a6b6a356 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 6 Oct 2021 11:11:55 -0700 Subject: [PATCH 5/9] Revert "Implement P1147R1 as Defect Report" This reverts commit 5b75b76dcf6804929291d2153c79ecba830dbd22. --- stl/inc/ostream | 4 ++-- stl/inc/yvals_core.h | 2 +- tests/std/tests/P1147R1_printing_volotile_pointers/env.lst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 44807718793..a5e41feccf8 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -454,12 +454,12 @@ public: return *this; } -#if _HAS_CXX20 // P1147R1 "Printing volatile Pointers" +#if _HAS_CXX23 // P1147R1 "Printing volatile Pointers" template // TRANSITION, ABI basic_ostream& operator<<(const volatile void* _Val) { return *this << (const_cast(_Val)); } -#endif // _HAS_CXX20 +#endif // _HAS_CXX23 #if _HAS_CXX17 // LWG-2221 "No formatted output operator for nullptr" template // TRANSITION, ABI diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index d63e72f1bbf..28e81720fe8 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -207,7 +207,6 @@ // P1115R3 erase()/erase_if() Return size_type // P1123R0 Atomic Compare-And-Exchange With Padding Bits For atomic_ref // P1135R6 The C++20 Synchronization Library -// P1147R1 Printing volatile Pointers // P1207R4 Movability Of Single-Pass Iterators // P1208R6 // P1209R0 erase_if(), erase() @@ -276,6 +275,7 @@ // P0943R6 Supporting C Atomics In C++ // P1048R1 is_scoped_enum // P1132R7 out_ptr(), inout_ptr() +// P1147R1 Printing volatile Pointers // P1425R4 Iterator Pair Constructors For stack And queue // P1679R3 contains() For basic_string/basic_string_view // P1682R3 to_underlying() For Enumerations diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst index 351a8293d9d..642f530ffad 100644 --- a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst +++ b/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\usual_20_matrix.lst +RUNALL_INCLUDE ..\usual_latest_matrix.lst From 1b91cb7d3d2201064c949a39d8a76c3fa3adae69 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 14 Oct 2021 18:40:06 +0700 Subject: [PATCH 6/9] eliminate inconsistencies identified during a code review. --- stl/inc/ostream | 4 +-- tests/std/test.lst | 2 +- .../env.lst | 0 .../test.cpp | 29 ++++++++++++++++ .../test.cpp | 34 ------------------- 5 files changed, 32 insertions(+), 37 deletions(-) rename tests/std/tests/{P1147R1_printing_volotile_pointers => P1147R1_printing_volatile_pointers}/env.lst (100%) create mode 100644 tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp delete mode 100644 tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp diff --git a/stl/inc/ostream b/stl/inc/ostream index 44807718793..731f3addd1d 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -454,14 +454,14 @@ public: return *this; } -#if _HAS_CXX20 // P1147R1 "Printing volatile Pointers" +#if _HAS_CXX20 template // TRANSITION, ABI basic_ostream& operator<<(const volatile void* _Val) { return *this << (const_cast(_Val)); } #endif // _HAS_CXX20 -#if _HAS_CXX17 // LWG-2221 "No formatted output operator for nullptr" +#if _HAS_CXX17 template // TRANSITION, ABI basic_ostream& operator<<(nullptr_t) { // insert a null pointer return *this << "nullptr"; diff --git a/tests/std/test.lst b/tests/std/test.lst index 9d7c3d4adca..7a4dbca8c4c 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -433,7 +433,7 @@ tests\P1135R6_atomic_wait_vista tests\P1135R6_barrier tests\P1135R6_latch tests\P1135R6_semaphore -tests\P1147R1_printing_volotile_pointers +tests\P1147R1_printing_volatile_pointers tests\P1165R1_consistently_propagating_stateful_allocators tests\P1208R6_source_location tests\P1423R3_char8_t_remediation diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/env.lst b/tests/std/tests/P1147R1_printing_volatile_pointers/env.lst similarity index 100% rename from tests/std/tests/P1147R1_printing_volotile_pointers/env.lst rename to tests/std/tests/P1147R1_printing_volatile_pointers/env.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..94d4534f675 --- /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 +std::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); +} diff --git a/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp deleted file mode 100644 index bd7ce84cedf..00000000000 --- a/tests/std/tests/P1147R1_printing_volotile_pointers/test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include -#include -#include - -using namespace std; - -std::string getExpected(int* ptr) { - ostringstream out; - out << ptr; - return out.str(); -} - -std::string getActual(volatile int* ptr) { - ostringstream out; - out << ptr; - return out.str(); -} - -void test(size_t value) { - int* p0 = reinterpret_cast(value); - volatile int* p1 = reinterpret_cast(p0); - - const string expected = getExpected(p0); - const string actual = getActual(p1); - - assert(expected == actual); -} - -int main() { - test(0xdeadbeef); -} From 05ddd1065a2ff314c1513f4deec7c303a8127fce Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 14 Oct 2021 18:51:46 +0700 Subject: [PATCH 7/9] extra `std::` --- tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp index 94d4534f675..7ad096821d1 100644 --- a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp +++ b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp @@ -8,7 +8,7 @@ using namespace std; template -std::string getTextValue(T* ptr) { +string getTextValue(T* ptr) { ostringstream out; out << ptr; return out.str(); From da28b995e2fd2210fce48fcc10f984c06d09972c Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 14 Oct 2021 18:53:35 +0700 Subject: [PATCH 8/9] '#include ` is not needed now --- tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp index 7ad096821d1..106073b8aba 100644 --- a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp +++ b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -#include #include using namespace std; From 705a340dd61121fd96d153923307fad319799509 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 14 Oct 2021 21:12:33 -0700 Subject: [PATCH 9/9] Code review feedback. --- stl/inc/ostream | 2 +- tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 46dcfd882d4..23049b5d156 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -457,7 +457,7 @@ public: #if _HAS_CXX23 template // TRANSITION, ABI basic_ostream& operator<<(const volatile void* _Val) { - return *this << (const_cast(_Val)); + return *this << const_cast(_Val); } #endif // _HAS_CXX23 diff --git a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp index 106073b8aba..c8820f5cc7e 100644 --- a/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp +++ b/tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp @@ -3,6 +3,7 @@ #include #include +#include using namespace std;