summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-08-04 12:48:22 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-08-04 19:37:56 +0100
commitdb33daa4677997399485176303406794dc900987 (patch)
tree0912af38ece0380ae88601a81f6995da5a609f6c /libstdc++-v3/testsuite
parent8e34d92ef29a175b84cc7f5185db43656ae762bb (diff)
libstdc++: Add comparisons to std::default_sentinel_t (LWG 3719)
This library defect was recently approved for C++23. libstdc++-v3/ChangeLog: * include/bits/fs_dir.h (directory_iterator): Add comparison with std::default_sentinel_t. Remove redundant operator!= for C++20. * (recursive_directory_iterator): Likewise. * include/bits/iterator_concepts.h [!__cpp_lib_concepts] (default_sentinel_t, default_sentinel): Define even if concepts are not supported. * include/bits/regex.h (regex_iterator): Add comparison with std::default_sentinel_t. Remove redundant operator!= for C++20. (regex_token_iterator): Likewise. (regex_token_iterator::_M_end_of_seq()): Add noexcept. * testsuite/27_io/filesystem/iterators/lwg3719.cc: New test. * testsuite/28_regex/iterators/regex_iterator/lwg3719.cc: New test. * testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3719.cc39
-rw-r--r--libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/lwg3719.cc29
-rw-r--r--libstdc++-v3/testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc29
3 files changed, 97 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3719.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3719.cc
new file mode 100644
index 00000000000..c19cddc74f9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3719.cc
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do run { target c++20 } }
+// { dg-require-filesystem-ts "" }
+
+#include <filesystem>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+// LWG 3719. Directory iterators should be usable with default sentinel
+
+void
+test_dir_iter()
+{
+ std::filesystem::directory_iterator d0;
+ VERIFY( d0 == std::default_sentinel );
+ std::filesystem::directory_iterator d1(".");
+ VERIFY( d1 != std::default_sentinel );
+
+ static_assert( noexcept(d0 == std::default_sentinel) );
+ static_assert( noexcept(d0 != std::default_sentinel) );
+}
+
+void
+test_recursive_dir_iter()
+{
+ std::filesystem::recursive_directory_iterator d0;
+ VERIFY( d0 == std::default_sentinel );
+ std::filesystem::recursive_directory_iterator d1(".");
+ VERIFY( d1 != std::default_sentinel );
+
+ static_assert( noexcept(d0 == std::default_sentinel) );
+ static_assert( noexcept(d0 != std::default_sentinel) );
+}
+
+int main()
+{
+ test_dir_iter();
+ test_recursive_dir_iter();
+}
diff --git a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/lwg3719.cc b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/lwg3719.cc
new file mode 100644
index 00000000000..e8c8f79364a
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/lwg3719.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do run { target c++20 } }
+
+#include <regex>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+// LWG 3719. Directory iterators should be usable with default sentinel
+
+void
+test_iter()
+{
+ std::sregex_token_iterator r0;
+ VERIFY( r0 == std::default_sentinel );
+ std::string haystack = "a needle in a haystack";
+ std::regex needle("needle");
+ std::sregex_iterator r1(haystack.begin(), haystack.end(), needle);
+ VERIFY( r1 != std::default_sentinel );
+ ++r1;
+ VERIFY( r1 == std::default_sentinel );
+
+ static_assert( noexcept(r0 == std::default_sentinel) ); // GCC extension
+ static_assert( noexcept(r0 != std::default_sentinel) ); // GCC extension
+}
+
+int main()
+{
+ test_iter();
+}
diff --git a/libstdc++-v3/testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc b/libstdc++-v3/testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc
new file mode 100644
index 00000000000..5c36acead74
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do run { target c++20 } }
+
+#include <regex>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+// LWG 3719. Directory iterators should be usable with default sentinel
+
+void
+test_iter()
+{
+ std::sregex_iterator r0;
+ VERIFY( r0 == std::default_sentinel );
+ std::string haystack = "a needle in a haystack";
+ std::regex needle("needle");
+ std::sregex_iterator r1(haystack.begin(), haystack.end(), needle);
+ VERIFY( r1 != std::default_sentinel );
+ ++r1;
+ VERIFY( r1 == std::default_sentinel );
+
+ static_assert( noexcept(r0 == std::default_sentinel) ); // GCC extension
+ static_assert( noexcept(r0 != std::default_sentinel) ); // GCC extension
+}
+
+int main()
+{
+ test_iter();
+}