[gcc r12-11040] libstdc++: Add missing parts of LWG 3480 for directory iterators [PR117560]
Jonathan Wakely
redi@gcc.gnu.org
Wed Apr 16 21:11:00 GMT 2025
https://gcc.gnu.org/g:5f3811fd50113571127b849325ab8f6c674158af
commit r12-11040-g5f3811fd50113571127b849325ab8f6c674158af
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Nov 14 01:14:44 2024 +0000
libstdc++: Add missing parts of LWG 3480 for directory iterators [PR117560]
It looks like I only read half the resolution of LWG 3480 and decided we
already supported it. As well as making the non-member overloads of end
take their parameters by value, we need some specializations of the
enable_borrowed_range and enable_view variable templates.
libstdc++-v3/ChangeLog:
PR libstdc++/117560
* include/bits/fs_dir.h (enable_borrowed_range, enable_view):
Define specializations for directory iterators, as per LWG 3480.
* testsuite/27_io/filesystem/iterators/lwg3480.cc: New test.
(cherry picked from commit eec6e8923586b9a54e37f32cef112d26d86e8f01)
Diff:
---
libstdc++-v3/include/bits/fs_dir.h | 22 ++++++++++++++++++++++
.../27_io/filesystem/iterators/lwg3480.cc | 16 ++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/libstdc++-v3/include/bits/fs_dir.h b/libstdc++-v3/include/bits/fs_dir.h
index 968a5cf52a05..822508ae83ed 100644
--- a/libstdc++-v3/include/bits/fs_dir.h
+++ b/libstdc++-v3/include/bits/fs_dir.h
@@ -39,6 +39,7 @@
#if __cplusplus >= 202002L
# include <compare> // std::strong_ordering
# include <bits/iterator_concepts.h> // std::default_sentinel_t
+# include <bits/ranges_base.h> // enable_view, enable_borrowed_range
#endif
namespace std _GLIBCXX_VISIBILITY(default)
@@ -626,6 +627,27 @@ _GLIBCXX_END_NAMESPACE_CXX11
extern template class
__shared_ptr<filesystem::recursive_directory_iterator::_Dir_stack>;
+#ifdef __cpp_lib_concepts // >= C++20
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// 3480. directory_iterator and recursive_directory_iterator are not ranges
+namespace ranges
+{
+ template<>
+ inline constexpr bool
+ enable_borrowed_range<filesystem::directory_iterator> = true;
+ template<>
+ inline constexpr bool
+ enable_borrowed_range<filesystem::recursive_directory_iterator> = true;
+
+ template<>
+ inline constexpr bool
+ enable_view<filesystem::directory_iterator> = true;
+ template<>
+ inline constexpr bool
+ enable_view<filesystem::recursive_directory_iterator> = true;
+} // namespace ranges
+#endif // concepts
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc
new file mode 100644
index 000000000000..15e0286fff6f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3480.cc
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++20 } }
+// { dg-require-filesystem-ts "" }
+
+// LWG 3480
+// directory_iterator and recursive_directory_iterator are not C++20 ranges
+
+#include <filesystem>
+
+namespace fs = std::filesystem;
+namespace rg = std::ranges;
+
+static_assert( rg::borrowed_range<fs::directory_iterator> );
+static_assert( rg::borrowed_range<fs::recursive_directory_iterator> );
+
+static_assert( rg::view<fs::directory_iterator> );
+static_assert( rg::view<fs::recursive_directory_iterator> );
More information about the Libstdc++-cvs
mailing list