forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
libstdc++-v3/testsuite/27_io/filesystem/iterators/lwg3719.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
29 changes: 29 additions & 0 deletions
29
libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/lwg3719.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
29 changes: 29 additions & 0 deletions
29
libstdc++-v3/testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |