Implement LWG 3096: path::lexically_relative is confused by trailing slashes

path("/dir/").lexically_relative("/dir"); now returns "." instead of ""

llvm-svn: 349885
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: ba62831f7cfd0d6111983772e7c06190e279dc03
diff --git a/src/filesystem/operations.cpp b/src/filesystem/operations.cpp
index 0b79ef1..e3bbc7b 100644
--- a/src/filesystem/operations.cpp
+++ b/src/filesystem/operations.cpp
@@ -1478,7 +1478,7 @@
     auto Elem = *PP;
     if (Elem == "..")
       --Count;
-    else if (Elem != ".")
+    else if (Elem != "." && Elem != "")
       ++Count;
   }
   return Count;
@@ -1492,8 +1492,7 @@
       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 @@
   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;