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 snextc();
15 
16 #include <streambuf>
17 #include <cassert>
18 
19 int uflow_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 
33 protected:
34     int_type uflow()
35     {
36         ++uflow_called;
37         return 'a';
38     }
39 };
40 
41 int main(int, char**)
42 {
43     {
44         test t;
45         assert(uflow_called == 0);
46         assert(t.snextc() == -1);
47         assert(uflow_called == 1);
48         char in[] = "ABC";
49         t.setg(in, in, in+sizeof(in));
50         assert(t.snextc() == 'B');
51         assert(uflow_called == 1);
52         assert(t.snextc() == 'C');
53         assert(uflow_called == 1);
54     }
55 
56   return 0;
57 }
58