summaryrefslogtreecommitdiffstats
path: root/libcxx/src/experimental/filesystem
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2017-07-05 03:37:05 +0000
committerEric Fiselier <eric@efcs.ca>2017-07-05 03:37:05 +0000
commit459877388bc48de1ea96033205531810b1fac59d (patch)
tree356286ac214bdf52b08fe50ee2ca4890f9b5de92 /libcxx/src/experimental/filesystem
parent34a7c3baf9d7d4312ac5c16662821ca48a60d9c3 (diff)
downloadbcm5719-llvm-459877388bc48de1ea96033205531810b1fac59d.tar.gz
bcm5719-llvm-459877388bc48de1ea96033205531810b1fac59d.zip
Implement LWG 2937 - equivalent("dne", "exists") is not an error
This patch speculatively implements the PR for LWG 2937, which fixes two issues with equivalent. (1) It makes equivalent("dne", "exists") an error. Previously only equivalent("dne", "dne") was an error and the former case was not (it returned false). Now equivalent reports an error when either input doesn't exist. (2) It makes equivalent(p1, p2) well-formed when `is_other(p1) && is_other(p2)`. Previously this was an error, but there is seemingly no reason why it should be on POSIX system. llvm-svn: 307117
Diffstat (limited to 'libcxx/src/experimental/filesystem')
-rw-r--r--libcxx/src/experimental/filesystem/operations.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp
index e9bc0eb6e30..f7e6cc794fe 100644
--- a/libcxx/src/experimental/filesystem/operations.cpp
+++ b/libcxx/src/experimental/filesystem/operations.cpp
@@ -426,17 +426,20 @@ void __current_path(const path& p, std::error_code *ec) {
bool __equivalent(const path& p1, const path& p2, std::error_code *ec)
{
+ auto make_unsupported_error = [&]() {
+ set_or_throw(make_error_code(errc::not_supported), ec,
+ "equivalent", p1, p2);
+ return false;
+ };
std::error_code ec1, ec2;
struct ::stat st1 = {};
struct ::stat st2 = {};
auto s1 = detail::posix_stat(p1.native(), st1, &ec1);
+ if (!exists(s1))
+ return make_unsupported_error();
auto s2 = detail::posix_stat(p2.native(), st2, &ec2);
-
- if ((!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))) {
- set_or_throw(make_error_code(errc::not_supported), ec,
- "equivalent", p1, p2);
- return false;
- }
+ if (!exists(s2))
+ return make_unsupported_error();
if (ec) ec->clear();
return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
}
OpenPOWER on IntegriCloud