[libcxx-commits] [libcxx] [libc++] Implement LWG3430 disallow implicit conversion of the source arguments to `std::filesystem::path` when constructing `std::basic_*fstream` (PR #85079)

Jonathan Wakely via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 11 10:58:45 PDT 2024


================
@@ -158,8 +158,8 @@ public:
     basic_fstream();
     explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
     explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
-    explicit basic_fstream(const filesystem::path& p,
-                           ios_base::openmode mode = ios_base::in|ios_base::out); C++17
+    template<class T>
+    explicit basic_fstream(const T& s, ios_base::openmode mode = ios_base::in | ios_base::out); // Since C++17
----------------
jwakely wrote:

That constructor already exists:

https://github.com/llvm/llvm-project/blob/a417b9b759960cc4d7b49e95ddc2ef129b5abe12/libcxx/include/fstream#L1413-L1415

It's definitely expected that you can't open an fstream with a `wstring`, the constructor aking a `filesystem::path` should not be used to convert "anything string-like, with any character type, in any encoding" into a file name with implicit allocations and character conversions.

https://github.com/llvm/llvm-project/pull/85079


More information about the libcxx-commits mailing list