std::filesystem::create_directory and std::filesystem::create_directories have inconsistent error handling #41028
Labels
bugzilla
Issues migrated from bugzilla
filesystem
C++17 std::filesystem
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Extended Description
std::filesystem::create_directories
andstd::filesystem::create_directory
behave differently in case there is a regular file with the name of the directory to create.While implementing a
std::filesystem
compatible library myself I found this while running my tests against the libc++ implementation:So for this code:
with an existing text file "foo.txt" the current result is:
(see runnable example here https://wandbox.org/permlink/Wa0Ie40k24rBwGmY)
No matter which of these two behaviours is the correct one, they should behave the same, in regard to this situation.
I know there is LWG issue 2935 (https://cplusplus.github.io/LWG/issue2935) that requested a change to handling this situation as no error, but I'm with Nicolai Josuttis, claiming this is not a good idea (see WG21 P1164R1, approved in Kona and adopted with cplusplus/draft#2703).
So in the end, all four operations should handle the case as an error.
(As additional information: GCCs libstdc++ had this behaviour swapped but inconsistent too, and adopted the P1164R1 solution.)
Thanks for your work!
The text was updated successfully, but these errors were encountered: