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