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 // explicit basic_ifstream(const filesystem::path& s,
28 //     ios_base::openmode mode = ios_base::in);
29 
30 #include <fstream>
31 #include <filesystem>
32 #include <cassert>
33 
34 #include "test_macros.h"
35 
36 namespace fs = std::filesystem;
37 
38 int main(int, char**) {
39   {
40     fs::path p;
41     static_assert(!std::is_convertible<fs::path, std::ifstream>::value,
42                   "ctor should be explicit");
43     static_assert(std::is_constructible<std::ifstream, fs::path const&,
44                                         std::ios_base::openmode>::value,
45                   "");
46   }
47   {
48     std::ifstream fs(fs::path("test.dat"));
49     double x = 0;
50     fs >> x;
51     assert(x == 3.25);
52   }
53   // std::ifstream(const fs::path&, std::ios_base::openmode) is tested in
54   // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
55   // which creates writable files.
56   {
57     std::wifstream fs(fs::path("test.dat"));
58     double x = 0;
59     fs >> x;
60     assert(x == 3.25);
61   }
62   // std::wifstream(const fs::path&, std::ios_base::openmode) is tested in
63   // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
64   // which creates writable files.
65 
66   return 0;
67 }
68