1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <ostream>
11 
12 // template <class charT, class traits = char_traits<charT> >
13 //   class basic_ostream;
14 
15 // pos_type tellp();
16 
17 #include <ostream>
18 #include <cassert>
19 
20 int seekoff_called = 0;
21 
22 template <class CharT>
23 struct testbuf
24     : public std::basic_streambuf<CharT>
25 {
26     typedef std::basic_streambuf<CharT> base;
testbuftestbuf27     testbuf() {}
28 
29 protected:
30 
31     typename base::pos_type
seekofftestbuf32     seekoff(typename base::off_type off, std::ios_base::seekdir way, std::ios_base::openmode which)
33     {
34         assert(off == 0);
35         assert(way == std::ios_base::cur);
36         assert(which == std::ios_base::out);
37         ++seekoff_called;
38         return 10;
39     }
40 };
41 
main()42 int main()
43 {
44     {
45         std::ostream os((std::streambuf*)0);
46         assert(os.tellp() == -1);
47     }
48     {
49         testbuf<char> sb;
50         std::ostream os(&sb);
51         assert(os.tellp() == 10);
52         assert(seekoff_called == 1);
53     }
54 }
55