From 920d0653706deb2ecf5ecdbc26556f529310e069 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 5 Jan 2018 22:48:00 +0000 Subject: [PATCH] PR libstdc++/83600 fix end iterator for unready std::match_results Backport from mainline 2017-12-27 Jonathan Wakely PR libstdc++/83600 * include/bits/regex.h (match_results::end()): Return valid iterator when not ready. * testsuite/28_regex/match_results/ctors/char/default.cc: Check that unready objects are empty and have equal begin and end iterators. * testsuite/28_regex/match_results/ctors/wchar_t/default.cc: Likewise. From-SVN: r256298 --- libstdc++-v3/ChangeLog | 10 ++++++++++ libstdc++-v3/include/bits/regex.h | 2 +- .../28_regex/match_results/ctors/char/default.cc | 4 ++++ .../28_regex/match_results/ctors/wchar_t/default.cc | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index aa81b4b705fa..0f233f2a076a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -3,6 +3,16 @@ Backport from mainline 2017-12-27 Jonathan Wakely + PR libstdc++/83600 + * include/bits/regex.h (match_results::end()): Return valid iterator + when not ready. + * testsuite/28_regex/match_results/ctors/char/default.cc: Check that + unready objects are empty and have equal begin and end iterators. + * testsuite/28_regex/match_results/ctors/wchar_t/default.cc: Likewise. + + Backport from mainline + 2017-12-27 Jonathan Wakely + PR libstdc++/83598 * include/bits/regex.h (basic_regex): Don't modify flags passed to constructors. diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 983bdef38712..cf7aa3ee4bff 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -1751,7 +1751,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 */ const_iterator end() const - { return _Base_type::end() - 3; } + { return _Base_type::end() - (empty() ? 0 : 3); } /** * @brief Gets an iterator to one-past-the-end of the collection. diff --git a/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/default.cc b/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/default.cc index 80b8bf767e57..82ae40dc2194 100644 --- a/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/default.cc +++ b/libstdc++-v3/testsuite/28_regex/match_results/ctors/char/default.cc @@ -32,6 +32,8 @@ void test01() std::cmatch cm; VERIFY( cm.size() == 0 ); VERIFY( !cm.ready() ); + VERIFY( cm.empty() ); + VERIFY( cm.begin() == cm.end() ); // PR libstdc++/83600 } void test02() @@ -41,6 +43,8 @@ void test02() std::smatch sm; VERIFY( sm.size() == 0 ); VERIFY( !sm.ready() ); + VERIFY( sm.empty() ); + VERIFY( sm.begin() == sm.end() ); // PR libstdc++/83600 } int diff --git a/libstdc++-v3/testsuite/28_regex/match_results/ctors/wchar_t/default.cc b/libstdc++-v3/testsuite/28_regex/match_results/ctors/wchar_t/default.cc index a4f68c1fc0db..88fe6a4f54c5 100644 --- a/libstdc++-v3/testsuite/28_regex/match_results/ctors/wchar_t/default.cc +++ b/libstdc++-v3/testsuite/28_regex/match_results/ctors/wchar_t/default.cc @@ -32,6 +32,8 @@ void test01() std::wcmatch cm; VERIFY( cm.size() == 0 ); VERIFY( !cm.ready() ); + VERIFY( cm.empty() ); + VERIFY( cm.begin() == cm.end() ); // PR libstdc++/83600 } void test02() @@ -41,6 +43,8 @@ void test02() std::wsmatch sm; VERIFY( sm.size() == 0 ); VERIFY( !sm.ready() ); + VERIFY( sm.empty() ); + VERIFY( sm.begin() == sm.end() ); // PR libstdc++/83600 } int -- 2.47.2