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 // UNSUPPORTED: c++03, c++11, c++14
10 // UNSUPPORTED: libcpp-has-no-filesystem-library
11 
12 // Filesystem is supported on Apple platforms starting with macosx10.15.
13 // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
14 
15 // FILE_DEPENDENCIES: test.dat
16 
17 // <fstream>
18 
19 // template <class charT, class traits = char_traits<charT> >
20 // class basic_ifstream
21 
22 // void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
23 
24 #include <fstream>
25 #include <filesystem>
26 #include <cassert>
27 
28 #include "test_macros.h"
29 
30 int main(int, char**) {
31   {
32     std::ifstream fs;
33     assert(!fs.is_open());
34     char c = 'a';
35     fs >> c;
36     assert(fs.fail());
37     assert(c == 'a');
38     fs.open(std::filesystem::path("test.dat"));
39     assert(fs.is_open());
40     fs >> c;
41     assert(c == 'r');
42   }
43 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44   {
45     std::wifstream fs;
46     assert(!fs.is_open());
47     wchar_t c = L'a';
48     fs >> c;
49     assert(fs.fail());
50     assert(c == L'a');
51     fs.open(std::filesystem::path("test.dat"));
52     assert(fs.is_open());
53     fs >> c;
54     assert(c == L'r');
55   }
56 #endif
57 
58   return 0;
59 }
60