[libcxx-commits] [libcxx] a9e0321 - [libc++][spaceship] P1614R2: Added `operator==` to `file_status`
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 12 09:53:56 PDT 2023
Author: Hristo Hristov
Date: 2023-06-12T19:53:50+03:00
New Revision: a9e0321ffed19cb74b5b238af0c155bab1b4093a
URL: https://github.com/llvm/llvm-project/commit/a9e0321ffed19cb74b5b238af0c155bab1b4093a
DIFF: https://github.com/llvm/llvm-project/commit/a9e0321ffed19cb74b5b238af0c155bab1b4093a.diff
LOG: [libc++][spaceship] P1614R2: Added `operator==` to `file_status`
Implemented parts of P1614R2:
- Added `operator==` to `file_status`
Reviewed By: #libc, Mordante
Differential Revision: https://reviews.llvm.org/D152647
Added:
libcxx/test/std/input.output/filesystems/class.file_status/file_status.status.eq.ops.cpp
Modified:
libcxx/docs/Status/SpaceshipProjects.csv
libcxx/include/__filesystem/file_status.h
libcxx/include/filesystem
Removed:
################################################################################
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index 9e40bac7a62c7..da26c2480abd2 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -181,11 +181,11 @@ Section,Description,Dependencies,Assignee,Complete
- `5.13 Clause 28: Localization library <https://wg21.link/p1614r2#clause-28-localization-library>`_,,,,
"| `[locale] <https://wg21.link/locale>`_
| `[locale.operators] <https://wg21.link/locale.operators>`_",| remove ops `locale`,None,Unassigned,|Not Started|
-- `5.14 Clause 29: Input/output library <https://wg21.link/p1614r2clause-29-inputoutput-library>`_,,,,
+- `5.14 Clause 29: Input/output library <https://wg21.link/p1614r2#clause-29-inputoutput-library>`_,,,,
| `[fs.filesystem.syn] <https://wg21.link/fs.filesystem.syn>`_,| `filesystem::space_info <https://reviews.llvm.org/D130861>`_,None,Adrian Vogelsgesang,|Complete|
"| `[fs.class.path] <https://wg21.link/fs.class.path>`_
| `[fs.path.nonmember] <https://wg21.link/fs.path.nonmember>`_",| `filesystem::path <https://reviews.llvm.org/D130859>`_,None,Adrian Vogelsgesang,|Complete|
-| `[fs.class.file.status] <https://wg21.link/fs.class.file.status>`_,|,None,Unassigned,|Not Started|
+| `[fs.class.file.status] <https://wg21.link/fs.class.file.status>`_,| `file_status <https://reviews.llvm.org/D152647>`_,None,Hristo Hristov,|Complete|
"| `[fs.class.directory.entry] <https://wg21.link/fs.class.directory.entry>`_
| `[fs.dir.entry.obs] <https://wg21.link/fs.dir.entry.obs>`_",| `filesystem::directory_entry <https://reviews.llvm.org/D130860>`_,None,Adrian Vogelsgesang,|Complete|
- `5.15 Clause 30: Regular expressions library <https://wg21.link/p1614r2#clause-30-regular-expressions-library>`_,,,,
diff --git a/libcxx/include/__filesystem/file_status.h b/libcxx/include/__filesystem/file_status.h
index 30ff55526f670..659f812516741 100644
--- a/libcxx/include/__filesystem/file_status.h
+++ b/libcxx/include/__filesystem/file_status.h
@@ -58,6 +58,14 @@ class _LIBCPP_TYPE_VIS file_status {
_LIBCPP_INLINE_VISIBILITY
void permissions(perms __p) noexcept { __prms_ = __p; }
+# if _LIBCPP_STD_VER >= 20
+
+ _LIBCPP_HIDE_FROM_ABI friend bool operator==(const file_status& __lhs, const file_status& __rhs) noexcept {
+ return __lhs.type() == __rhs.type() && __lhs.permissions() == __rhs.permissions();
+ }
+
+# endif
+
private:
file_type __ft_;
perms __prms_;
diff --git a/libcxx/include/filesystem b/libcxx/include/filesystem
index addf28a7e6e97..133c7bea5c802 100644
--- a/libcxx/include/filesystem
+++ b/libcxx/include/filesystem
@@ -248,7 +248,31 @@
recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
recursive_directory_iterator end(recursive_directory_iterator) noexcept;
- class file_status;
+ class file_status {
+ public:
+ // [fs.file.status.cons], constructors and destructor
+ file_status() noexcept : file_status(file_type::none) {}
+ explicit file_status(file_type ft,
+ perms prms = perms::unknown) noexcept;
+ file_status(const file_status&) noexcept = default;
+ file_status(file_status&&) noexcept = default;
+ ~file_status();
+
+ // assignments
+ file_status& operator=(const file_status&) noexcept = default;
+ file_status& operator=(file_status&&) noexcept = default;
+
+ // [fs.file.status.mods], modifiers
+ void type(file_type ft) noexcept;
+ void permissions(perms prms) noexcept;
+
+ // [fs.file.status.obs], observers
+ file_type type() const noexcept;
+ perms permissions() const noexcept;
+
+ friend bool operator==(const file_status& lhs, const file_status& rhs) noexcept
+ { return lhs.type() == rhs.type() && lhs.permissions() == rhs.permissions(); } // C++20
+ };
struct space_info
{
diff --git a/libcxx/test/std/input.output/filesystems/class.file_status/file_status.status.eq.ops.cpp b/libcxx/test/std/input.output/filesystems/class.file_status/file_status.status.eq.ops.cpp
new file mode 100644
index 0000000000000..6b45a39d4a81b
--- /dev/null
+++ b/libcxx/test/std/input.output/filesystems/class.file_status/file_status.status.eq.ops.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03 c++11 c++14 c++17
+
+// <filesystem>
+
+// class file_status
+
+// friend bool operator==(const file_status& lhs, const file_status& rhs) noexcept
+// { return lhs.type() == rhs.type() && lhs.permissions() == rhs.permissions(); } // C++20
+
+#include <cassert>
+#include <filesystem>
+
+#include "test_macros.h"
+
+void test() {
+ {
+ std::fileystem::file_status f1;
+ std::fileystem::file_status f2;
+
+ assert(testEquality(f1, f2, true));
+ }
+ {
+ std::fileystem::file_status f1{std::filesystem::file_type::regular, std::filesystem::perms::owner_read};
+ std::fileystem::file_status f2{std::filesystem::file_type::regular, std::filesystem::perms::owner_read};
+
+ assert(testEquality(f1, f2, true));
+ }
+ {
+ std::fileystem::file_status f1{std::filesystem::file_type::regular, std::filesystem::perms::owner_read};
+ std::fileystem::file_status f2{std::filesystem::file_type::none, std::filesystem::perms::owner_read};
+
+ assert(testEquality(f1, f2, false));
+ }
+ {
+ std::fileystem::file_status f1{std::filesystem::file_type::regular, std::filesystem::perms::owner_read};
+ std::fileystem::file_status f2{std::filesystem::file_type::regular, std::filesystem::perms::owner_write};
+
+ assert(testEquality(f1, f2, false));
+ }
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
More information about the libcxx-commits
mailing list