1998a5c88SEric Fiselier //===----------------------------------------------------------------------===//
2998a5c88SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6998a5c88SEric Fiselier //
7998a5c88SEric Fiselier //===----------------------------------------------------------------------===//
8998a5c88SEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10*a7f9895cSLouis Dionne // UNSUPPORTED: no-filesystem
11933518ffSLouis Dionne 
12933518ffSLouis Dionne // Filesystem is supported on Apple platforms starting with macosx10.15.
13c360553cSLouis Dionne // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
14933518ffSLouis Dionne 
157efbd851SLouis Dionne // FILE_DEPENDENCIES: test.dat
16998a5c88SEric Fiselier 
17998a5c88SEric Fiselier // <fstream>
18998a5c88SEric Fiselier 
19998a5c88SEric Fiselier // template <class charT, class traits = char_traits<charT> >
20998a5c88SEric Fiselier // class basic_ifstream
21998a5c88SEric Fiselier 
22998a5c88SEric Fiselier // explicit basic_ifstream(const filesystem::path& s,
23998a5c88SEric Fiselier //     ios_base::openmode mode = ios_base::in);
24998a5c88SEric Fiselier 
25998a5c88SEric Fiselier #include <fstream>
26998a5c88SEric Fiselier #include <filesystem>
27998a5c88SEric Fiselier #include <cassert>
28998a5c88SEric Fiselier 
297fc6a556SMarshall Clow #include "test_macros.h"
307fc6a556SMarshall Clow 
31998a5c88SEric Fiselier namespace fs = std::filesystem;
32998a5c88SEric Fiselier 
main(int,char **)332df59c50SJF Bastien int main(int, char**) {
34998a5c88SEric Fiselier   {
35998a5c88SEric Fiselier     fs::path p;
36998a5c88SEric Fiselier     static_assert(!std::is_convertible<fs::path, std::ifstream>::value,
37998a5c88SEric Fiselier                   "ctor should be explicit");
38998a5c88SEric Fiselier     static_assert(std::is_constructible<std::ifstream, fs::path const&,
39998a5c88SEric Fiselier                                         std::ios_base::openmode>::value,
40998a5c88SEric Fiselier                   "");
41998a5c88SEric Fiselier   }
42998a5c88SEric Fiselier   {
43998a5c88SEric Fiselier     std::ifstream fs(fs::path("test.dat"));
44998a5c88SEric Fiselier     double x = 0;
45998a5c88SEric Fiselier     fs >> x;
46998a5c88SEric Fiselier     assert(x == 3.25);
47998a5c88SEric Fiselier   }
48998a5c88SEric Fiselier   // std::ifstream(const fs::path&, std::ios_base::openmode) is tested in
49998a5c88SEric Fiselier   // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
50998a5c88SEric Fiselier   // which creates writable files.
51f4c1258dSLouis Dionne 
52f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
53998a5c88SEric Fiselier   {
54998a5c88SEric Fiselier     std::wifstream fs(fs::path("test.dat"));
55998a5c88SEric Fiselier     double x = 0;
56998a5c88SEric Fiselier     fs >> x;
57998a5c88SEric Fiselier     assert(x == 3.25);
58998a5c88SEric Fiselier   }
59998a5c88SEric Fiselier   // std::wifstream(const fs::path&, std::ios_base::openmode) is tested in
60998a5c88SEric Fiselier   // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
61998a5c88SEric Fiselier   // which creates writable files.
62f4c1258dSLouis Dionne #endif
632df59c50SJF Bastien 
642df59c50SJF Bastien   return 0;
65998a5c88SEric Fiselier }
66