Index: include/ostream =================================================================== --- include/ostream +++ include/ostream @@ -56,6 +56,7 @@ basic_ostream& operator<<(double f); basic_ostream& operator<<(long double f); basic_ostream& operator<<(const void* p); + basic_ostream& operator<<(nullptr_t); basic_ostream& operator<<(basic_streambuf* sb); // 27.7.2.7 Unformatted output: @@ -140,6 +141,7 @@ #include #include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -218,6 +220,10 @@ basic_ostream& operator<<(const void* __p); basic_ostream& operator<<(basic_streambuf* __sb); + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + basic_ostream& operator<<(nullptr_t) + { return *this << (const void*)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.arithmetic/nullptr_t.pass.cpp =================================================================== --- /dev/null +++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template > +// class basic_ostream; + +// operator<<(nullptr_t); + +#include +#include +#include + +template +class testbuf + : public std::basic_streambuf +{ + typedef std::basic_streambuf base; + std::basic_string str_; +public: + testbuf() + { + } + + std::basic_string str() const + {return std::basic_string(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = static_cast(str_.size()); + str_.push_back(static_cast(__c)); + str_.resize(str_.capacity()); + base::setp(const_cast(str_.data()), + const_cast(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + std::ostream os((std::streambuf*)0); + std::nullptr_t n = nullptr; + os << n; + assert(os.bad()); + assert(os.fail()); + } + { + testbuf sb; + std::ostream os(&sb); + std::nullptr_t n = nullptr; + os << n; + assert(os.good()); + std::string s(sb.str()); + + // Implementation defined. Instead of validating the output, + // at least ensure that it does not generate an empty string. + assert(!s.empty()); + } + { + testbuf sb; + std::ostream os(&sb); + std::nullptr_t const n = nullptr; + os << n; + assert(os.good()); + } +} Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -356,7 +356,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