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 // <ostream> 10 11 // template <class charT, class traits = char_traits<charT> > 12 // class basic_ostream; 13 14 // pos_type tellp(); 15 16 #include <ostream> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 int seekoff_called = 0; 22 23 template <class CharT> 24 struct testbuf 25 : public std::basic_streambuf<CharT> 26 { 27 typedef std::basic_streambuf<CharT> base; testbuftestbuf28 testbuf() {} 29 30 protected: 31 32 typename base::pos_type seekofftestbuf33 seekoff(typename base::off_type off, std::ios_base::seekdir way, std::ios_base::openmode which) 34 { 35 assert(off == 0); 36 assert(way == std::ios_base::cur); 37 assert(which == std::ios_base::out); 38 ++seekoff_called; 39 return 10; 40 } 41 }; 42 main(int,char **)43int main(int, char**) 44 { 45 { 46 std::ostream os((std::streambuf*)0); 47 assert(os.tellp() == -1); 48 } 49 { 50 testbuf<char> sb; 51 std::ostream os(&sb); 52 assert(os.tellp() == 10); 53 assert(seekoff_called == 1); 54 } 55 56 return 0; 57 } 58