Index: include/ostream =================================================================== --- include/ostream +++ include/ostream @@ -218,6 +218,10 @@ basic_ostream& operator<<(const void* __p); basic_ostream& operator<<(basic_streambuf* __sb); + _LIBCPP_INLINE_VISIBILITY + basic_ostream& operator<<(nullptr_t) + { return *this << static_cast("nullptr\0"); } + // 27.7.2.7 Unformatted output: basic_ostream& put(char_type __c); basic_ostream& write(const char_type* __s, streamsize __n); Index: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp =================================================================== --- test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp +++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp @@ -67,6 +67,13 @@ 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; }