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}}
14998a5c88SEric Fiselier 
15998a5c88SEric Fiselier // <fstream>
16998a5c88SEric Fiselier 
17998a5c88SEric Fiselier // plate <class charT, class traits = char_traits<charT> >
18998a5c88SEric Fiselier // class basic_ofstream
19998a5c88SEric Fiselier 
20998a5c88SEric Fiselier // explicit basic_ofstream(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
21998a5c88SEric Fiselier 
22998a5c88SEric Fiselier #include <fstream>
23998a5c88SEric Fiselier #include <filesystem>
24998a5c88SEric Fiselier #include <cassert>
257fc6a556SMarshall Clow #include "test_macros.h"
26998a5c88SEric Fiselier #include "platform_support.h"
27998a5c88SEric Fiselier 
28998a5c88SEric Fiselier namespace fs = std::filesystem;
29998a5c88SEric Fiselier 
main(int,char **)302df59c50SJF Bastien int main(int, char**) {
31998a5c88SEric Fiselier   fs::path p = get_temp_file_name();
32998a5c88SEric Fiselier   {
33998a5c88SEric Fiselier     static_assert(!std::is_convertible<fs::path, std::ofstream>::value,
34998a5c88SEric Fiselier                   "ctor should be explicit");
35998a5c88SEric Fiselier     static_assert(std::is_constructible<std::ofstream, fs::path const&,
36998a5c88SEric Fiselier                                         std::ios_base::openmode>::value,
37998a5c88SEric Fiselier                   "");
38998a5c88SEric Fiselier   }
39998a5c88SEric Fiselier   {
40998a5c88SEric Fiselier     std::ofstream stream(p);
41998a5c88SEric Fiselier     stream << 3.25;
42998a5c88SEric Fiselier   }
43998a5c88SEric Fiselier   {
44998a5c88SEric Fiselier     std::ifstream stream(p);
45998a5c88SEric Fiselier     double x = 0;
46998a5c88SEric Fiselier     stream >> x;
47998a5c88SEric Fiselier     assert(x == 3.25);
48998a5c88SEric Fiselier   }
49998a5c88SEric Fiselier   {
50998a5c88SEric Fiselier     std::ifstream stream(p, std::ios_base::out);
51998a5c88SEric Fiselier     double x = 0;
52998a5c88SEric Fiselier     stream >> x;
53998a5c88SEric Fiselier     assert(x == 3.25);
54998a5c88SEric Fiselier   }
55f1537708SMartin Storsjö   std::remove(p.string().c_str());
56f4c1258dSLouis Dionne 
57f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
58998a5c88SEric Fiselier   {
59998a5c88SEric Fiselier     std::wofstream stream(p);
60998a5c88SEric Fiselier     stream << 3.25;
61998a5c88SEric Fiselier   }
62998a5c88SEric Fiselier   {
63998a5c88SEric Fiselier     std::wifstream stream(p);
64998a5c88SEric Fiselier     double x = 0;
65998a5c88SEric Fiselier     stream >> x;
66998a5c88SEric Fiselier     assert(x == 3.25);
67998a5c88SEric Fiselier   }
68998a5c88SEric Fiselier   {
69998a5c88SEric Fiselier     std::wifstream stream(p, std::ios_base::out);
70998a5c88SEric Fiselier     double x = 0;
71998a5c88SEric Fiselier     stream >> x;
72998a5c88SEric Fiselier     assert(x == 3.25);
73998a5c88SEric Fiselier   }
74f1537708SMartin Storsjö   std::remove(p.string().c_str());
75f4c1258dSLouis Dionne #endif
762df59c50SJF Bastien 
772df59c50SJF Bastien   return 0;
78998a5c88SEric Fiselier }
79