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 //===----------------------------------------------------------------------===//
8 
9 // <iterator>
10 
11 // class ostreambuf_iterator
12 
13 // bool failed() const throw();
14 
15 #include <cassert>
16 #include <iterator>
17 #include <sstream>
18 
19 #include "test_macros.h"
20 
21 template <typename Char, typename Traits = std::char_traits<Char> >
22 struct my_streambuf : public std::basic_streambuf<Char,Traits> {
23     typedef typename std::basic_streambuf<Char,Traits>::int_type  int_type;
24     typedef typename std::basic_streambuf<Char,Traits>::char_type char_type;
25 
my_streambufmy_streambuf26     my_streambuf() {}
sputcmy_streambuf27     int_type sputc(char_type) { return Traits::eof(); }
28 };
29 
main(int,char **)30 int main(int, char**)
31 {
32     {
33         my_streambuf<char> buf;
34         std::ostreambuf_iterator<char> i(&buf);
35         i = 'a';
36         assert(i.failed());
37     }
38 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
39     {
40         my_streambuf<wchar_t> buf;
41         std::ostreambuf_iterator<wchar_t> i(&buf);
42         i = L'a';
43         assert(i.failed());
44     }
45 #endif
46 
47   return 0;
48 }
49