Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc

raw
1 // Copyright (C) 2014-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++11 } }
19 // { dg-require-fileio "" }
20 // { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
21
22 // C++11 27.9.1.7 basic_ifstream constructors [ifstream.cons]
23
24 #include <fstream>
25 #include <sstream>
26 #include <testsuite_hooks.h>
27
28 void
29 read(std::istream& in, std::ostream& out)
30 {
31 std::string s;
32 for (int i=0; i < 10; ++i)
33 {
34 getline(in, s);
35 out << s << '\n';
36 }
37 }
38
39 void
40 test01()
41 {
42 std::string const name = "thirty_years_among_the_dead_preproc.txt";
43 std::ostringstream ss0;
44 {
45 std::ifstream f0(name);
46 read(f0, ss0);
47 }
48 std::ifstream f0(name);
49 std::ifstream f1 = std::move(f0);
50 VERIFY( !f0.is_open() );
51 VERIFY( f1.is_open() );
52 std::ostringstream ss1;
53 read(f1, ss1);
54 VERIFY( ss0.str() == ss1.str() );
55 }
56
57 void
58 test02()
59 {
60 #ifdef _GLIBCXX_USE_WCHAR_T
61 std::wifstream f0("thirty_years_among_the_dead_preproc.txt");
62 std::wifstream f1 = std::move(f0);
63 VERIFY( f1.is_open() );
64 #endif
65 }
66
67 int
68 main()
69 {
70 test01();
71 test02();
72 }