K-ballo created this revision. With effects equivalent to `os << (const void*)nullptr`.
https://reviews.llvm.org/D33776 Files: include/ostream test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/nullptr_t.pass.cpp www/cxx1z_status.html
Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -356,7 +356,7 @@ <tr><td></td><td></td><td></td><td></td></tr> <tr><td><a href="http://wg21.link/LWG2062">2062</a></td><td>Effect contradictions w/o no-throw guarantee of std::function swaps</td><td>Issaquah</td><td>Complete</td></tr> <tr><td><a href="http://wg21.link/LWG2166">2166</a></td><td>Heap property underspecified?</td><td>Issaquah</td><td></td></tr> - <tr><td><a href="http://wg21.link/LWG2221">2221</a></td><td>No formatted output operator for nullptr</td><td>Issaquah</td><td></td></tr> + <tr><td><a href="http://wg21.link/LWG2221">2221</a></td><td>No formatted output operator for nullptr</td><td>Issaquah</td><td>Complete</td></tr> <tr><td><a href="http://wg21.link/LWG2223">2223</a></td><td>shrink_to_fit effect on iterator validity</td><td>Issaquah</td><td>Complete</td></tr> <tr><td><a href="http://wg21.link/LWG2261">2261</a></td><td>Are containers required to use their 'pointer' type internally?</td><td>Issaquah</td><td></td></tr> <tr><td><a href="http://wg21.link/LWG2394">2394</a></td><td>locale::name specification unclear - what is implementation-defined?</td><td>Issaquah</td><td>Complete</td></tr> 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. +// +//===----------------------------------------------------------------------===// + +// <ostream> + +// template <class charT, class traits = char_traits<charT> > +// class basic_ostream; + +// operator<<(nullptr_t); + +#include <ostream> +#include <cstddef> +#include <cassert> + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(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<int>(str_.size()); + str_.push_back(static_cast<CharT>(__c)); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(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<char> 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<char> sb; + std::ostream os(&sb); + std::nullptr_t const n = nullptr; + os << n; + assert(os.good()); + } +} 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<char_type,traits>* sb); // 27.7.2.7 Unformatted output: @@ -140,6 +141,7 @@ #include <locale> #include <iterator> #include <bitset> +#include <cstddef> #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<char_type, traits_type>* __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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits