<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - std::experimental::filesystem::remove() reports error instead of returning false if path does not exist"
href="https://bugs.llvm.org/show_bug.cgi?id=35780">35780</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::experimental::filesystem::remove() reports error instead of returning false if path does not exist
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>andrewgunnerson@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>The C++17 standard requires that filesystem::remove() returns false if the
given path does not exist ([fs.op.remove]), but the current implementation will
always report an error if the POSIX remove() function returns -1.
<a href="https://github.com/llvm-mirror/libcxx/blob/05e705f9ecc348e42a710325743dd3bccbc89569/src/experimental/filesystem/operations.cpp#L662-L669">https://github.com/llvm-mirror/libcxx/blob/05e705f9ecc348e42a710325743dd3bccbc89569/src/experimental/filesystem/operations.cpp#L662-L669</a>
I think this could be fixed by reporting an error only if POSIX remove()
returns -1 and errno != ENOENT.
Test case:
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main(int argc, char *argv[])
{
std::cout << "Deleted: " << fs::remove(argv[1]) << '\n';
}
Output:
$ LD_LIBRARY_PATH=/stuff/svn/llvm/build/lib ./a.out /tmp/non-existent-path
terminating with uncaught exception of type
std::experimental::filesystem::v1::filesystem_error:
std::experimental::filesystem::remove: No such file or directory
[1] 12425 abort (core dumped) LD_LIBRARY_PATH=/stuff/svn/llvm/build/lib
./a.out /tmp/non-existent-path</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>