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 @@ -181,11 +181,11 @@ - `5.13 Clause 28: Localization library `_,,,, "| `[locale] `_ | `[locale.operators] `_",| remove ops `locale`,None,Unassigned,|Not Started| -- `5.14 Clause 29: Input/output library `_,,,, +- `5.14 Clause 29: Input/output library `_,,,, | `[fs.filesystem.syn] `_,| `filesystem::space_info `_,None,Adrian Vogelsgesang,|Complete| "| `[fs.class.path] `_ | `[fs.path.nonmember] `_",| `filesystem::path `_,None,Adrian Vogelsgesang,|Complete| -| `[fs.class.file.status] `_,|,None,Unassigned,|Not Started| +| `[fs.class.file.status] `_,| `file_status `_,None,Hristo Hristov,|Complete| "| `[fs.class.directory.entry] `_ | `[fs.dir.entry.obs] `_",| `filesystem::directory_entry `_,None,Adrian Vogelsgesang,|Complete| - `5.15 Clause 30: Regular expressions library `_,,,, diff --git a/libcxx/include/__filesystem/file_status.h b/libcxx/include/__filesystem/file_status.h --- a/libcxx/include/__filesystem/file_status.h +++ b/libcxx/include/__filesystem/file_status.h @@ -58,6 +58,14 @@ _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 --- 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 --- /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 + +// + +// 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 +#include + +#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; +}