mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-22 07:51:39 +08:00
Move old test into test/libcxx, and implement new version of test for ostreambuf_iterator::failed. Fixes PR#37245. Thanks to Billy O'Neill for the bug report.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@330955 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
32
test/libcxx/iterators/failed.pass.cpp
Normal file
32
test/libcxx/iterators/failed.pass.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// class ostreambuf_iterator
|
||||
|
||||
// bool failed() const throw();
|
||||
//
|
||||
// Extension: constructing from NULL is UB; we just make it a failed iterator
|
||||
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::ostreambuf_iterator<char> i(nullptr);
|
||||
assert(i.failed());
|
||||
}
|
||||
{
|
||||
std::ostreambuf_iterator<wchar_t> i(nullptr);
|
||||
assert(i.failed());
|
||||
}
|
||||
}
|
@@ -17,14 +17,27 @@
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
template <typename Char, typename Traits = std::char_traits<Char> >
|
||||
struct my_streambuf : public std::basic_streambuf<Char,Traits> {
|
||||
typedef typename std::basic_streambuf<Char,Traits>::int_type int_type;
|
||||
typedef typename std::basic_streambuf<Char,Traits>::char_type char_type;
|
||||
|
||||
my_streambuf() {}
|
||||
int_type sputc(char_type) { return Traits::eof(); }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::ostreambuf_iterator<char> i(nullptr);
|
||||
my_streambuf<char> buf;
|
||||
std::ostreambuf_iterator<char> i(&buf);
|
||||
i = 'a';
|
||||
assert(i.failed());
|
||||
}
|
||||
{
|
||||
std::ostreambuf_iterator<wchar_t> i(nullptr);
|
||||
my_streambuf<wchar_t> buf;
|
||||
std::ostreambuf_iterator<wchar_t> i(&buf);
|
||||
i = L'a';
|
||||
assert(i.failed());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user