[Arm] Fix generating code with UB in NeonEmitter (#121802)
[llvm-project.git] / libcxx / test / std / input.output / file.streams / fstreams / filebuf.virtuals / pbackfail.pass.cpp
blob03aff1681227c8c09b79514d2bb9b2078be8e4b9
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 //===----------------------------------------------------------------------===//
9 // <fstream>
11 // int_type pbackfail(int_type c = traits::eof());
13 // FILE_DEPENDENCIES: underflow.dat
15 #include <fstream>
16 #include <cassert>
18 #include "test_macros.h"
20 template <class CharT>
21 struct test_buf
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);}
37 int main(int, char**)
40 test_buf<char> f;
41 assert(f.open("underflow.dat", std::ios_base::in) != 0);
42 assert(f.is_open());
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');
53 test_buf<char> f;
54 assert(f.open("underflow.dat", std::ios_base::in | std::ios_base::out) != 0);
55 assert(f.is_open());
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');
66 return 0;