[Bug libstdc++/83626] New: std::experimental::filesystem::remove_all throws exception instead of returning 0 if path doesn't exist
chillermillerlong at hotmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 30 02:18:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83626
Bug ID: 83626
Summary: std::experimental::filesystem::remove_all throws
exception instead of returning 0 if path doesn't exist
Product: gcc
Version: 7.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: chillermillerlong at hotmail dot com
Target Milestone: ---
The current std::experimental::filesystem::remove_all() implementation seems to
throw an exception if the specified path does not exist. I may be
misunderstanding the standard, but § 30.10.15.31 in the latest C++17 draft says
that the function "Recursively deletes the contents of p if it exists, then
deletes file p itself" and returns "The number of files removed". It seems to
me that the function should return 0 if the path does not exist. (Indeed, this
is how boost::filesystem::remove_all() behaves.)
The following sample program demonstrates the behavior.
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main(int argc, char *argv[])
{
std::cout << "Deleted " << fs::remove_all(argv[1]) << " paths\n";
}
If I pass it a path that doesn't exist, it throws an exception:
$ g++ fs.cpp -std=c++17 -lstdc++fs
$ ./a.out /tmp/non-existent
terminate called after throwing an instance of
'std::experimental::filesystem::v1::__cxx11::filesystem_error'
what(): filesystem error: cannot remove all: No such file or directory
[/tmp/non-existent]
[1] 9386 abort (core dumped) ./a.out /tmp/non-existent
More information about the Gcc-bugs
mailing list