Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement P1147R1 "Printing volatile Pointers" #2262

Merged
merged 12 commits into from
Oct 20, 2021
9 changes: 8 additions & 1 deletion stl/inc/ostream
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,14 @@ public:
return *this;
}

#if _HAS_CXX17 // LWG-2221 "No formatted output operator for nullptr"
#if _HAS_CXX23
template <class = void> // TRANSITION, ABI
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
basic_ostream& operator<<(const volatile void* _Val) {
return *this << const_cast<const void*>(_Val);
}
#endif // _HAS_CXX23

#if _HAS_CXX17
template <class = void> // TRANSITION, ABI
basic_ostream& operator<<(nullptr_t) { // insert a null pointer
return *this << "nullptr";
Expand Down
1 change: 1 addition & 0 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P1147R1_printing_volatile_pointers/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_latest_matrix.lst
29 changes: 29 additions & 0 deletions tests/std/tests/P1147R1_printing_volatile_pointers/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <sstream>
#include <string>

using namespace std;

template <typename T>
string getTextValue(T* ptr) {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
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);
}