[libcxx-commits] [libcxx] [libc++] Fix different slashes confuses lexically_proximate and lexically_relative (PR #99780)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 20 23:05:51 PDT 2024


https://github.com/RichardLuo0 updated https://github.com/llvm/llvm-project/pull/99780

>From 6e40c544bfa33923c766ff7459af3e377b79cbf9 Mon Sep 17 00:00:00 2001
From: RichardLuo <22096448+RichardLuo0 at users.noreply.github.com>
Date: Sun, 21 Jul 2024 03:12:56 +0800
Subject: [PATCH 1/3] [libc++] Use forward slash for root dir to fix
 lexically_relative on windows

---
 libcxx/src/filesystem/path_parser.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libcxx/src/filesystem/path_parser.h b/libcxx/src/filesystem/path_parser.h
index 06623696452da..b38df13a3f7df 100644
--- a/libcxx/src/filesystem/path_parser.h
+++ b/libcxx/src/filesystem/path_parser.h
@@ -174,10 +174,7 @@ struct PathParser {
     case PS_AtEnd:
       return PATHSTR("");
     case PS_InRootDir:
-      if (RawEntry[0] == '\\')
-        return PATHSTR("\\");
-      else
-        return PATHSTR("/");
+      return PATHSTR("/");
     case PS_InTrailingSep:
       return PATHSTR("");
     case PS_InRootName:

>From 4efa8ffdabe5877941d334576275d37ccbcf3d43 Mon Sep 17 00:00:00 2001
From: RichardLuo <22096448+RichardLuo0 at users.noreply.github.com>
Date: Sun, 21 Jul 2024 13:59:26 +0800
Subject: [PATCH 2/3] [libc++] the root_directory() still returns the original
 root_directory

---
 libcxx/src/filesystem/path.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/filesystem/path.cpp b/libcxx/src/filesystem/path.cpp
index b2019521377ed..63b4c76bf5073 100644
--- a/libcxx/src/filesystem/path.cpp
+++ b/libcxx/src/filesystem/path.cpp
@@ -55,7 +55,7 @@ string_view_t path::__root_directory() const {
   if (PP.State_ == PathParser::PS_InRootName)
     ++PP;
   if (PP.State_ == PathParser::PS_InRootDir)
-    return *PP;
+    return PP.RawEntry;
   return {};
 }
 

>From 572ed17cb895614a7f9855fe5592a38b73f88c95 Mon Sep 17 00:00:00 2001
From: RichardLuo <22096448+RichardLuo0 at users.noreply.github.com>
Date: Sun, 21 Jul 2024 14:03:24 +0800
Subject: [PATCH 3/3] change the tests

---
 .../path.member/path.decompose/path.decompose.pass.cpp    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
index 6013172e0c671..9a1b581fa112c 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
@@ -128,11 +128,11 @@ const PathDecomposeTestcase PathTestCases[] =
 #endif
     , {"prn:", {"prn:"}, "", "", "", "prn:", "", "prn:"}
 #ifdef _WIN32
-    , {"c:\\", {"c:", "\\"}, "c:\\", "c:", "\\", "", "c:\\", ""}
-    , {"c:\\foo", {"c:", "\\", "foo"}, "c:\\", "c:", "\\", "foo", "c:\\", "foo"}
+    , {"c:\\", {"c:", "/"}, "c:\\", "c:", "\\", "", "c:\\", ""}
+    , {"c:\\foo", {"c:", "/", "foo"}, "c:\\", "c:", "\\", "foo", "c:\\", "foo"}
     , {"c:foo\\", {"c:", "foo", ""}, "c:", "c:", "", "foo\\", "c:foo", ""}
-    , {"c:\\foo\\", {"c:", "\\", "foo", ""}, "c:\\", "c:", "\\", "foo\\", "c:\\foo", ""}
-    , {"c:\\foo/",  {"c:", "\\", "foo", ""}, "c:\\", "c:", "\\", "foo/", "c:\\foo", ""}
+    , {"c:\\foo\\", {"c:", "/", "foo", ""}, "c:\\", "c:", "\\", "foo\\", "c:\\foo", ""}
+    , {"c:\\foo/",  {"c:", "/", "foo", ""}, "c:\\", "c:", "\\", "foo/", "c:\\foo", ""}
     , {"c:/foo\\bar", {"c:", "/", "foo", "bar"}, "c:\\", "c:", "\\", "foo\\bar", "c:/foo", "bar"}
 #else
     , {"c:\\", {"c:\\"}, "", "", "", "c:\\", "", "c:\\"}



More information about the libcxx-commits mailing list