From a5996e8dc96c57bbd34334387fc9ea26091d22e9 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 26 Apr 2018 16:16:45 +0000 Subject: [PATCH] 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 --- test/libcxx/iterators/failed.pass.cpp | 32 +++++++++++++++++++ .../ostreambuf.iter.ops/failed.pass.cpp | 17 ++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/libcxx/iterators/failed.pass.cpp diff --git a/test/libcxx/iterators/failed.pass.cpp b/test/libcxx/iterators/failed.pass.cpp new file mode 100644 index 000000000..2e4717b38 --- /dev/null +++ b/test/libcxx/iterators/failed.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// class ostreambuf_iterator + +// bool failed() const throw(); +// +// Extension: constructing from NULL is UB; we just make it a failed iterator + +#include +#include +#include + +int main() +{ + { + std::ostreambuf_iterator i(nullptr); + assert(i.failed()); + } + { + std::ostreambuf_iterator i(nullptr); + assert(i.failed()); + } +} diff --git a/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp b/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp index 9d93bad37..5cc9cf928 100644 --- a/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp +++ b/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp @@ -17,14 +17,27 @@ #include #include +template > +struct my_streambuf : public std::basic_streambuf { + typedef typename std::basic_streambuf::int_type int_type; + typedef typename std::basic_streambuf::char_type char_type; + + my_streambuf() {} + int_type sputc(char_type) { return Traits::eof(); } + }; + int main() { { - std::ostreambuf_iterator i(nullptr); + my_streambuf buf; + std::ostreambuf_iterator i(&buf); + i = 'a'; assert(i.failed()); } { - std::ostreambuf_iterator i(nullptr); + my_streambuf buf; + std::ostreambuf_iterator i(&buf); + i = L'a'; assert(i.failed()); } }