Skip to content

Commit

Permalink
Implement P1147R1 "Printing volatile Pointers" (#2262)
Browse files Browse the repository at this point in the history
Co-authored-by: Casey Carter <Casey@Carter.net>
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
3 people authored Oct 20, 2021
1 parent ebd229f commit 486a8a1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
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
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 @@ -276,6 +276,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 @@ -434,6 +434,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) {
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);
}

0 comments on commit 486a8a1

Please sign in to comment.