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 sputbackc(char_type c); 15 16 #include <streambuf> 17 #include <cassert> 18 19 int pbackfail_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 pbackfail(int_type = traits_type::eof()) 35 { 36 ++pbackfail_called; 37 return 'a'; 38 } 39 }; 40 41 int main(int, char**) 42 { 43 { 44 test t; 45 assert(pbackfail_called == 0); 46 assert(t.sputbackc('A') == 'a'); 47 assert(pbackfail_called == 1); 48 char in[] = "ABC"; 49 t.setg(in, in+1, in+sizeof(in)); 50 assert(t.sputbackc('A') == 'A'); 51 assert(pbackfail_called == 1); 52 assert(t.sputbackc('A') == 'a'); 53 assert(pbackfail_called == 2); 54 } 55 56 return 0; 57 } 58