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