diff --git a/libcxx/include/ostream b/libcxx/include/ostream --- a/libcxx/include/ostream +++ b/libcxx/include/ostream @@ -225,9 +225,13 @@ basic_ostream& operator<<(basic_streambuf* __sb); +#if _LIBCPP_STD_VER > 14 +// LWG 2221 - nullptr. This is not backported to older standards modes. +// See https://reviews.llvm.org/D127033 for more info on the rationale. _LIBCPP_INLINE_VISIBILITY basic_ostream& operator<<(nullptr_t) { return *this << "nullptr"; } +#endif // 27.7.2.7 Unformatted output: basic_ostream& put(char_type __c); 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 --- 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,13 +67,17 @@ os << &sb2; assert(sb.str() == "testing..."); } - { // LWG 2221 - nullptr +#if TEST_STD_VER > 14 +// LWG 2221 - nullptr. This is not backported to older standards modes. +// See https://reviews.llvm.org/D127033 for more info on the rationale. + { testbuf sb; std::ostream os(&sb); os << nullptr; assert(sb.str().size() != 0); LIBCPP_ASSERT(sb.str() == "nullptr"); } +#endif return 0; }