forked from OSchip/llvm-project
Implement LWG 2221 - No formatted output operator for nullptr. Reviewed as https://reviews.llvm.org/D44263
llvm-svn: 342566
This commit is contained in:
parent
29bf94d86f
commit
4a71f9cfcc
|
@ -56,6 +56,7 @@ public:
|
||||||
basic_ostream& operator<<(double f);
|
basic_ostream& operator<<(double f);
|
||||||
basic_ostream& operator<<(long double f);
|
basic_ostream& operator<<(long double f);
|
||||||
basic_ostream& operator<<(const void* p);
|
basic_ostream& operator<<(const void* p);
|
||||||
|
basic_ostream<charT, traits>& operator<<(nullptr_t); // C++17
|
||||||
basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
|
basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
|
||||||
|
|
||||||
// 27.7.2.7 Unformatted output:
|
// 27.7.2.7 Unformatted output:
|
||||||
|
@ -216,6 +217,7 @@ public:
|
||||||
basic_ostream& operator<<(double __f);
|
basic_ostream& operator<<(double __f);
|
||||||
basic_ostream& operator<<(long double __f);
|
basic_ostream& operator<<(long double __f);
|
||||||
basic_ostream& operator<<(const void* __p);
|
basic_ostream& operator<<(const void* __p);
|
||||||
|
basic_ostream& operator<<(nullptr_t);
|
||||||
basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
|
basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
|
||||||
|
|
||||||
// 27.7.2.7 Unformatted output:
|
// 27.7.2.7 Unformatted output:
|
||||||
|
@ -709,6 +711,14 @@ basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _CharT, class _Traits>
|
||||||
|
basic_ostream<_CharT, _Traits>&
|
||||||
|
basic_ostream<_CharT, _Traits>::operator<<(nullptr_t)
|
||||||
|
{
|
||||||
|
return *this << "(nullptr)";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class _CharT, class _Traits>
|
template<class _CharT, class _Traits>
|
||||||
basic_ostream<_CharT, _Traits>&
|
basic_ostream<_CharT, _Traits>&
|
||||||
__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
|
__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
|
||||||
|
@ -742,7 +752,6 @@ __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
|
||||||
return __os;
|
return __os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class _CharT, class _Traits>
|
template<class _CharT, class _Traits>
|
||||||
basic_ostream<_CharT, _Traits>&
|
basic_ostream<_CharT, _Traits>&
|
||||||
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
|
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// template<class charT, class traits>
|
||||||
|
// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, nullptr_t);
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
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 ch = base::traits_type::eof())
|
||||||
|
{
|
||||||
|
if (ch != base::traits_type::eof())
|
||||||
|
{
|
||||||
|
int n = static_cast<int>(str_.size());
|
||||||
|
str_.push_back(ch);
|
||||||
|
str_.resize(str_.capacity());
|
||||||
|
base::setp(const_cast<CharT*>(str_.data()),
|
||||||
|
const_cast<CharT*>(str_.data() + str_.size()));
|
||||||
|
base::pbump(n+1);
|
||||||
|
}
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::wostream os((std::wstreambuf*)0);
|
||||||
|
os << nullptr;
|
||||||
|
assert(os.bad());
|
||||||
|
assert(os.fail());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
testbuf<char> sb;
|
||||||
|
std::ostream os(&sb);
|
||||||
|
assert(sb.str().length() == 0);
|
||||||
|
os << nullptr;
|
||||||
|
assert(sb.str().length() > 0);
|
||||||
|
LIBCPP_ASSERT(sb.str() == "(nullptr)"); // output is an implementation-defined NTCTS
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
testbuf<wchar_t> sb;
|
||||||
|
std::wostream os(&sb);
|
||||||
|
assert(sb.str().length() == 0);
|
||||||
|
os << nullptr;
|
||||||
|
assert(sb.str().length() > 0);
|
||||||
|
LIBCPP_ASSERT(sb.str() == L"(nullptr)"); // output is an implementation-defined NTCTS
|
||||||
|
}
|
||||||
|
}
|
|
@ -365,7 +365,7 @@
|
||||||
<tr><td></td><td></td><td></td><td></td></tr>
|
<tr><td></td><td></td><td></td><td></td></tr>
|
||||||
<tr><td><a href="https://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="https://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="https://wg21.link/LWG2166">2166</a></td><td>Heap property underspecified?</td><td>Issaquah</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2166">2166</a></td><td>Heap property underspecified?</td><td>Issaquah</td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2221">2221</a></td><td>No formatted output operator for nullptr</td><td>Issaquah</td><td></td></tr>
|
<tr><td><a href="https://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="https://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="https://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="https://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="https://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="https://wg21.link/LWG2394">2394</a></td><td>locale::name specification unclear - what is implementation-defined?</td><td>Issaquah</td><td>Complete</td></tr>
|
<tr><td><a href="https://wg21.link/LWG2394">2394</a></td><td>locale::name specification unclear - what is implementation-defined?</td><td>Issaquah</td><td>Complete</td></tr>
|
||||||
|
@ -504,7 +504,7 @@
|
||||||
<!-- <tr><td></td><td></td><td></td><td></td></tr> -->
|
<!-- <tr><td></td><td></td><td></td><td></td></tr> -->
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p>Last Updated: 3-Aug-2018</p>
|
<p>Last Updated: 19-Sep-2018</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue