summaryrefslogtreecommitdiff
path: root/libcxx
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-12-21 04:25:40 +0000
committerEric Fiselier <eric@efcs.ca>2018-12-21 04:25:40 +0000
commit75de022a13f7cf2b6e1349ac70012c0124e23653 (patch)
tree0ec6a20a7d68a03c4c85a8e4db4eab94a513c7cf /libcxx
parent8cf803bd99b588b1baae20efca8e239adb4512d6 (diff)
Implement LWG 3096: path::lexically_relative is confused by trailing slashes
path("/dir/").lexically_relative("/dir"); now returns "." instead of ""
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/src/filesystem/operations.cpp9
-rw-r--r--libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp4
-rw-r--r--libcxx/www/cxx2a_status.html2
3 files changed, 9 insertions, 6 deletions
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 0b79ef1cdac..e3bbc7b64b8 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -1478,7 +1478,7 @@ static int DetermineLexicalElementCount(PathParser PP) {
auto Elem = *PP;
if (Elem == "..")
--Count;
- else if (Elem != ".")
+ else if (Elem != "." && Elem != "")
++Count;
}
return Count;
@@ -1492,8 +1492,7 @@ path path::lexically_relative(const path& base) const {
return PP.State != PPBase.State &&
(PP.inRootPath() || PPBase.inRootPath());
};
- if (PP.State == PathParser::PS_InRootName &&
- PPBase.State == PathParser::PS_InRootName) {
+ if (PP.inRootName() && PPBase.inRootName()) {
if (*PP != *PPBase)
return {};
} else if (CheckIterMismatchAtBase())
@@ -1525,6 +1524,10 @@ path path::lexically_relative(const path& base) const {
if (ElemCount < 0)
return {};
+ // if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
+ if (ElemCount == 0 && (PP.atEnd() || *PP == ""))
+ return ".";
+
// return a path constructed with 'n' dot-dot elements, followed by the the
// elements of '*this' after the mismatch.
path Result;
diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
index 52c577bc8a7..f4e1d2f74df 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp
@@ -40,8 +40,8 @@ int main() {
{"a", "/", ""},
{"//net", "a", ""},
{"a", "//net", ""},
- {"//net/", "//net", ""},
- {"//net", "//net/", ".."},
+ {"//net/", "//net", "."},
+ {"//net", "//net/", "."},
{"//base", "a", ""},
{"a", "a", "."},
{"a/b", "a/b", "."},
diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html
index 1a072c9b054..63ae029ed4a 100644
--- a/libcxx/www/cxx2a_status.html
+++ b/libcxx/www/cxx2a_status.html
@@ -271,7 +271,7 @@
<tr><td><a href="https://wg21.link/LWG3038">3038</a></td><td><tt>polymorphic_allocator::allocate</tt> should not allow integer overflow to create vulnerabilities</td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3054">3054</a></td><td><tt>uninitialized_copy</tt> appears to not be able to meet its exception-safety guarantee</td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3065">3065</a></td><td>LWG 2989 missed that all <tt>path</tt>'s other operators should be hidden friends as well</td><td>San Diego</td><td>Complete</td></tr>
- <tr><td><a href="https://wg21.link/LWG3096">3096</a></td><td><tt>path::lexically_relative</tt> is confused by trailing slashes</td><td>San Diego</td><td></td></tr>
+ <tr><td><a href="https://wg21.link/LWG3096">3096</a></td><td><tt>path::lexically_relative</tt> is confused by trailing slashes</td><td>San Diego</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3116">3116</a></td><td><tt><i>OUTERMOST_ALLOC_TRAITS</i></tt> needs <tt>remove_reference_t</tt></td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3122">3122</a></td><td><tt>__cpp_lib_chrono_udls</tt> was accidentally dropped</td><td>San Diego</td><td><i>We've already made the update; but we don't support all the test macros. When we do, this will be closed</i></td></tr>
<tr><td><a href="https://wg21.link/LWG3127">3127</a></td><td><tt>basic_osyncstream::rdbuf</tt> needs a <tt>const_cast</tt></td><td>San Diego</td><td></td></tr>