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