Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / file.streams / fstreams / filebuf.assign / nonmember_swap_min.pass.cpp
blob6981360cef4ff7d4c747c9dcf4e6d30b1b024d91
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 // This tests that swapping filebufs works correctly even when the small buffer
10 // optimization is in use (https://github.com/llvm/llvm-project/issues/49282).
12 // <fstream>
14 // template <class charT, class traits = char_traits<charT> >
15 // class basic_filebuf
17 // template <class charT, class traits>
18 // void
19 // swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
21 #include <fstream>
22 #include <cassert>
23 #include "test_macros.h"
24 #include "platform_support.h"
26 int main(int, char**)
28 std::string tmpA = get_temp_file_name();
29 std::string tmpB = get_temp_file_name();
32 std::ofstream sa(tmpA), sb(tmpB);
33 sa << "AAAA";
34 sb << "BBBB";
37 std::filebuf f1;
38 assert(f1.open(tmpA, std::ios_base::in) != 0);
39 assert(f1.is_open());
40 f1.pubsetbuf(0, 0);
42 std::filebuf f2;
43 assert(f2.open(tmpB, std::ios_base::in) != 0);
44 assert(f2.is_open());
45 f2.pubsetbuf(0, 0);
47 assert(f1.sgetc() == 'A');
48 assert(f2.sgetc() == 'B');
50 swap(f1, f2);
52 assert(f1.is_open());
53 assert(f2.is_open());
55 assert(f1.sgetc() == 'B');
56 assert(f2.sgetc() == 'A');
58 std::remove(tmpA.c_str());
59 std::remove(tmpB.c_str());
61 return 0;