Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / output.streams / ostream.manip / ends.pass.cpp
blobb005c8e7126c90a44a0d0fe9e6de702f08cdd88a
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <ostream>
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_ostream;
14 // template <class charT, class traits>
15 // basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
17 #include <ostream>
18 #include <cassert>
20 #include "test_macros.h"
22 template <class CharT>
23 class testbuf
24 : public std::basic_streambuf<CharT>
26 typedef std::basic_streambuf<CharT> base;
27 std::basic_string<CharT> str_;
28 public:
29 testbuf()
33 std::basic_string<CharT> str() const
34 {return std::basic_string<CharT>(base::pbase(), base::pptr());}
36 protected:
38 virtual typename base::int_type
39 overflow(typename base::int_type ch = base::traits_type::eof())
41 if (ch != base::traits_type::eof())
43 int n = static_cast<int>(str_.size());
44 str_.push_back(static_cast<CharT>(ch));
45 str_.resize(str_.capacity());
46 base::setp(const_cast<CharT*>(str_.data()),
47 const_cast<CharT*>(str_.data() + str_.size()));
48 base::pbump(n+1);
50 return ch;
54 int main(int, char**)
57 testbuf<char> sb;
58 std::ostream os(&sb);
59 std::ends(os);
60 assert(sb.str().size() == 1);
61 assert(sb.str().back() == 0);
62 assert(os.good());
64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
66 testbuf<wchar_t> sb;
67 std::wostream os(&sb);
68 std::ends(os);
69 assert(sb.str().size() == 1);
70 assert(sb.str().back() == 0);
71 assert(os.good());
73 #endif
75 return 0;