diff options
author | RichardLuo <CommAdama@outlook.com> | 2024-08-16 21:26:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 09:26:38 -0400 |
commit | aa427b1aae445ed46d9f60c5e2eaac61bdf76be3 (patch) | |
tree | 88f9e8c6b36d8cbddf5150962e129666043cb0ed /libcxx/src | |
parent | abdc2b17d2dbb49397cbe4023f199f63461c2a97 (diff) | |
download | llvm-aa427b1aae445ed46d9f60c5e2eaac61bdf76be3.zip llvm-aa427b1aae445ed46d9f60c5e2eaac61bdf76be3.tar.gz llvm-aa427b1aae445ed46d9f60c5e2eaac61bdf76be3.tar.bz2 |
[libc++] Fix backslash as root dir breaks lexically_relative, lexically_proximate and hash_value on Windows (#99780)
Various functions like hash_value, lexically_proximate and lexically_relative
would incorrectly handle backslashes in the root directory on Windows, causing
behavior that is inconsistent with the equality comparison for a path.
Diffstat (limited to 'libcxx/src')
-rw-r--r-- | libcxx/src/filesystem/path.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libcxx/src/filesystem/path.cpp b/libcxx/src/filesystem/path.cpp index b201952..5874244 100644 --- a/libcxx/src/filesystem/path.cpp +++ b/libcxx/src/filesystem/path.cpp @@ -267,7 +267,7 @@ path path::lexically_relative(const path& base) const { // Find the first mismatching element auto PP = PathParser::CreateBegin(__pn_); auto PPBase = PathParser::CreateBegin(base.__pn_); - while (PP && PPBase && PP.State_ == PPBase.State_ && *PP == *PPBase) { + while (PP && PPBase && PP.State_ == PPBase.State_ && (*PP == *PPBase || PP.inRootDir())) { ++PP; ++PPBase; } @@ -368,7 +368,8 @@ size_t hash_value(const path& __p) noexcept { size_t hash_value = 0; hash<string_view_t> hasher; while (PP) { - hash_value = __hash_combine(hash_value, hasher(*PP)); + string_view_t Part = PP.inRootDir() ? PATHSTR("/") : *PP; + hash_value = __hash_combine(hash_value, hasher(Part)); ++PP; } return hash_value; |