diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -41,6 +41,8 @@ Improvements and New Features ----------------------------- +* Implemented ``operator<=>`` for ``std::filesystem::path`` + Deprecations and Removals ------------------------- diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv --- a/libcxx/docs/Status/SpaceshipProjects.csv +++ b/libcxx/docs/Status/SpaceshipProjects.csv @@ -73,7 +73,7 @@ | `[time.zone.link.nonmembers] `_","| chrono::time_zone | chrono::leap_second | chrono::time_zone_link",A ```` implementation,Unassigned,|Not Started| -| `[fs.path.nonmember] `_,| filesystem::path,None,Unassigned,|Not Started| +| `[fs.path.nonmember] `_,| filesystem::path,,Adrian Vogelsgesang,|Complete| | `[fs.dir.entry.obs] `_,| filesystem::directory_entry,None,Unassigned,|Not Started| | `[re.submatch.op] `_,| sub_match,None,Unassigned,|Not Started| | `[thread.thread.id] `_,| thread::id,None,Unassigned,|Not Started| diff --git a/libcxx/include/__filesystem/path.h b/libcxx/include/__filesystem/path.h --- a/libcxx/include/__filesystem/path.h +++ b/libcxx/include/__filesystem/path.h @@ -1038,6 +1038,7 @@ friend _LIBCPP_HIDE_FROM_ABI bool operator==(const path& __lhs, const path& __rhs) noexcept { return __lhs.__compare(__rhs.__pn_) == 0; } +#if _LIBCPP_STD_VER <= 17 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const path& __lhs, const path& __rhs) noexcept { return __lhs.__compare(__rhs.__pn_) != 0; } @@ -1053,6 +1054,11 @@ friend _LIBCPP_HIDE_FROM_ABI bool operator>=(const path& __lhs, const path& __rhs) noexcept { return __lhs.__compare(__rhs.__pn_) >= 0; } +#else // _LIBCPP_STD_VER <= 17 + friend _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) <=> 0; + } +#endif // _LIBCPP_STD_VER <= 17 friend _LIBCPP_HIDE_FROM_ABI path operator/(const path& __lhs, const path& __rhs) { path __result(__lhs); diff --git a/libcxx/include/filesystem b/libcxx/include/filesystem --- a/libcxx/include/filesystem +++ b/libcxx/include/filesystem @@ -20,11 +20,12 @@ size_t hash_value(const path& p) noexcept; bool operator==(const path& lhs, const path& rhs) noexcept; - bool operator!=(const path& lhs, const path& rhs) noexcept; - bool operator< (const path& lhs, const path& rhs) noexcept; - bool operator<=(const path& lhs, const path& rhs) noexcept; - bool operator> (const path& lhs, const path& rhs) noexcept; - bool operator>=(const path& lhs, const path& rhs) noexcept; + bool operator!=(const path& lhs, const path& rhs) noexcept; // removed in C++20 + bool operator< (const path& lhs, const path& rhs) noexcept; // removed in C++20 + bool operator<=(const path& lhs, const path& rhs) noexcept; // removed in C++20 + bool operator> (const path& lhs, const path& rhs) noexcept; // removed in C++20 + bool operator>=(const path& lhs, const path& rhs) noexcept; // removed in C++20 + strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept; // C++20 path operator/ (const path& lhs, const path& rhs); diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp --- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp @@ -22,10 +22,10 @@ // bool operator<=(path const&, path const&) noexcept; // bool operator> (path const&, path const&) noexcept; // bool operator>=(path const&, path const&) noexcept; +// strong_ordering operator<=>(path const&, path const&) noexcept; // // size_t hash_value(path const&) noexcept; - #include "filesystem_include.h" #include #include @@ -118,6 +118,9 @@ assert((p1 <= p2) == (E <= 0)); assert((p1 > p2) == (E > 0)); assert((p1 >= p2) == (E >= 0)); +#if TEST_STD_VER > 17 + assert((p1 <=> p2) == (E <=> 0)); +#endif // Check signatures ASSERT_NOEXCEPT(p1 == p2); @@ -126,6 +129,9 @@ ASSERT_NOEXCEPT(p1 <= p2); ASSERT_NOEXCEPT(p1 > p2); ASSERT_NOEXCEPT(p1 >= p2); +#if TEST_STD_VER > 17 + ASSERT_NOEXCEPT(p1 <=> p2); +#endif } { // check hash values auto h1 = hash_value(p1);