TyanNN created this revision. TyanNN added a reviewer: EricWF. Herald added a subscriber: cfe-commits.
Previously it thrown an error if the file didn't exist. PR#35780 Repository: rCXX libc++ https://reviews.llvm.org/D41830 Files: src/experimental/filesystem/operations.cpp test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp Index: test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp =================================================================== --- test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp +++ test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/filesystem> + +// class path + +#define _LIBCPP_DEBUG 0 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (void)::AssertCount++) +int AssertCount = 0; + +#include <experimental/filesystem> +#include <cassert> +#include <fstream> + +namespace fs = std::experimental::filesystem; + +int main() +{ + using namespace fs; + + path nFile("nonexistant.file"); + assert(remove(nFile) == false); + + path tempFilePath = temp_directory_path(); + tempFilePath += path("existingFile"); + + std::ofstream theTempFile(tempFilePath); + theTempFile.close(); + + assert(remove(tempFilePath) == true); + + return 0; +} Index: src/experimental/filesystem/operations.cpp =================================================================== --- src/experimental/filesystem/operations.cpp +++ src/experimental/filesystem/operations.cpp @@ -661,8 +661,9 @@ bool __remove(const path& p, std::error_code *ec) { if (ec) ec->clear(); + if (::remove(p.c_str()) == -1) { - set_or_throw(ec, "remove", p); + if (errno != ENOENT) set_or_throw(ec, "remove", p); return false; } return true;
Index: test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp =================================================================== --- test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp +++ test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/filesystem> + +// class path + +#define _LIBCPP_DEBUG 0 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (void)::AssertCount++) +int AssertCount = 0; + +#include <experimental/filesystem> +#include <cassert> +#include <fstream> + +namespace fs = std::experimental::filesystem; + +int main() +{ + using namespace fs; + + path nFile("nonexistant.file"); + assert(remove(nFile) == false); + + path tempFilePath = temp_directory_path(); + tempFilePath += path("existingFile"); + + std::ofstream theTempFile(tempFilePath); + theTempFile.close(); + + assert(remove(tempFilePath) == true); + + return 0; +} Index: src/experimental/filesystem/operations.cpp =================================================================== --- src/experimental/filesystem/operations.cpp +++ src/experimental/filesystem/operations.cpp @@ -661,8 +661,9 @@ bool __remove(const path& p, std::error_code *ec) { if (ec) ec->clear(); + if (::remove(p.c_str()) == -1) { - set_or_throw(ec, "remove", p); + if (errno != ENOENT) set_or_throw(ec, "remove", p); return false; } return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits