Index: src/experimental/filesystem/operations.cpp =================================================================== --- src/experimental/filesystem/operations.cpp +++ src/experimental/filesystem/operations.cpp @@ -661,8 +661,10 @@ 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 (ec != nullptr && *ec != errc::no_such_file_or_directory) + set_or_throw(ec, "remove", p); return false; } return true; @@ -695,8 +697,12 @@ std::error_code mec; auto count = remove_all_impl(p, mec); if (mec) { - set_or_throw(mec, ec, "remove_all", p); - return static_cast(-1); + if (mec != errc::no_such_file_or_directory) { + set_or_throw(mec, ec, "remove_all", p); + return static_cast(-1); + } else { + return static_cast(0); + } } if (ec) ec->clear(); return count; Index: test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw_on_nonexistant.pass.cpp =================================================================== --- test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw_on_nonexistant.pass.cpp +++ test/libcxx/experimental/filesystem/class.path/path.remove/remove_should_not_throw_on_nonexistant.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class path + +#define _LIBCPP_DEBUG 0 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (void)::AssertCount++) +int AssertCount = 0; + +#include +#include +#include + +namespace fs = std::experimental::filesystem; + +int main() +{ + using namespace fs; + + // filesystem::remove test + + 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); + + // filesystem::remove_all + + assert(remove_all(nFile) == 0); + + std::ofstream theTempFile2(tempFilePath); + theTempFile2.close(); + assert(remove_all(tempFilePath) == 1); + + return 0; +}