From 3c125fe821cc0306dbe9820595a06e8b5e502a2c Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 1 Jul 2019 16:20:25 +0000 Subject: [PATCH] Implement LWG2221: 'Formatted output for nullptr_t' Reviewed as: https://reviews.llvm.org/D63053 llvm-svn: 364802 --- libcxx/include/ostream | 5 +++++ .../ostream.formatted/ostream.inserters/streambuf.pass.cpp | 7 +++++++ libcxx/www/cxx1z_status.html | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libcxx/include/ostream b/libcxx/include/ostream index b20ac34a3d87..e6cf9c970f72 100644 --- a/libcxx/include/ostream +++ b/libcxx/include/ostream @@ -56,6 +56,7 @@ public: basic_ostream& operator<<(long double f); basic_ostream& operator<<(const void* p); basic_ostream& operator<<(basic_streambuf* sb); + basic_ostream& operator<<(nullptr_t); // 27.7.2.7 Unformatted output: basic_ostream& put(char_type c); @@ -218,6 +219,10 @@ public: basic_ostream& operator<<(const void* __p); basic_ostream& operator<<(basic_streambuf* __sb); + _LIBCPP_INLINE_VISIBILITY + basic_ostream& operator<<(nullptr_t) + { return *this << "nullptr"; } + // 27.7.2.7 Unformatted output: basic_ostream& put(char_type __c); basic_ostream& write(const char_type* __s, streamsize __n); diff --git a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp index daf5ba102a8d..af411157e9cb 100644 --- a/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp +++ b/libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp @@ -67,6 +67,13 @@ int main(int, char**) os << &sb2; assert(sb.str() == "testing..."); } + { // LWG 2221 - nullptr + testbuf sb; + std::ostream os(&sb); + os << nullptr; + assert(sb.str().size() != 0); + LIBCPP_ASSERT(sb.str() == "nullptr"); + } return 0; } diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index 94950ded285c..5427d4880463 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -364,7 +364,7 @@ 2062Effect contradictions w/o no-throw guarantee of std::function swapsIssaquahComplete 2166Heap property underspecified?Issaquah - 2221No formatted output operator for nullptrIssaquah + 2221No formatted output operator for nullptrIssaquahComplete 2223shrink_to_fit effect on iterator validityIssaquahComplete 2261Are containers required to use their 'pointer' type internally?Issaquah 2394locale::name specification unclear - what is implementation-defined?IssaquahComplete