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 // <streambuf>
10 
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_streambuf;
13 
14 // int_type sputc(char_type c);
15 
16 #include <streambuf>
17 #include <cassert>
18 
19 int overflow_called = 0;
20 
21 struct test
22     : public std::basic_streambuf<char>
23 {
24     typedef std::basic_streambuf<char> base;
25 
26     test() {}
27 
28     void setg(char* gbeg, char* gnext, char* gend)
29     {
30         base::setg(gbeg, gnext, gend);
31     }
32     void setp(char* pbeg, char* pend)
33     {
34         base::setp(pbeg, pend);
35     }
36 
37 protected:
38     int_type overflow(int_type = traits_type::eof())
39     {
40         ++overflow_called;
41         return 'a';
42     }
43 };
44 
45 int main(int, char**)
46 {
47     {
48         test t;
49         assert(overflow_called == 0);
50         assert(t.sputc('A') == 'a');
51         assert(overflow_called == 1);
52         char out[3] = {0};
53         t.setp(out, out+sizeof(out));
54         assert(t.sputc('A') == 'A');
55         assert(overflow_called == 1);
56         assert(out[0] == 'A');
57         assert(t.sputc('B') == 'B');
58         assert(overflow_called == 1);
59         assert(out[0] == 'A');
60         assert(out[1] == 'B');
61     }
62 
63   return 0;
64 }
65