1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // int_type pbackfail(int_type c = traits::eof());
13 // FILE_DEPENDENCIES: underflow.dat
18 #include "test_macros.h"
20 template <class CharT
>
22 : public std::basic_filebuf
<CharT
>
24 typedef std::basic_filebuf
<CharT
> base
;
25 typedef typename
base::char_type char_type
;
26 typedef typename
base::int_type int_type
;
27 typedef typename
base::traits_type traits_type
;
29 char_type
* eback() const {return base::eback();}
30 char_type
* gptr() const {return base::gptr();}
31 char_type
* egptr() const {return base::egptr();}
32 void gbump(int n
) {base::gbump(n
);}
34 virtual int_type
pbackfail(int_type c
= traits_type::eof()) {return base::pbackfail(c
);}
41 assert(f
.open("underflow.dat", std::ios_base::in
) != 0);
43 assert(f
.sbumpc() == '1');
44 assert(f
.sgetc() == '2');
45 typename test_buf
<char>::int_type pbackResult
= f
.pbackfail('a');
46 LIBCPP_ASSERT(pbackResult
== -1);
47 if (pbackResult
!= -1) {
48 assert(f
.sbumpc() == 'a');
49 assert(f
.sgetc() == '2');
54 assert(f
.open("underflow.dat", std::ios_base::in
| std::ios_base::out
) != 0);
56 assert(f
.sbumpc() == '1');
57 assert(f
.sgetc() == '2');
58 typename test_buf
<char>::int_type pbackResult
= f
.pbackfail('a');
59 LIBCPP_ASSERT(pbackResult
== 'a');
60 if (pbackResult
!= -1) {
61 assert(f
.sbumpc() == 'a');
62 assert(f
.sgetc() == '2');