From: Tim Shen Date: Wed, 9 Nov 2016 22:11:32 +0000 (+0000) Subject: regex.h (regex_iterator::regex_iterator()): Define end() as _M_pregex == nullptr. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7ce69e5a7156b6ada7064e6b4e75da82d582982a;p=gcc.git regex.h (regex_iterator::regex_iterator()): Define end() as _M_pregex == nullptr. * libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()): Define end() as _M_pregex == nullptr. * libstdc++-v3/include/bits/regex.tcc (regex_iterator::operator==(), regex_iterator::operator++()): Fix operator==() and operator++() to look at null-ness of _M_pregex on both sides. * testsuite/28_regex/regression.cc: New testcase. From-SVN: r242025 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 61dafba43e9..f405ccd1569 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2016-11-09 Tim Shen + + * libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()): + Define end() as _M_pregex == nullptr. + * libstdc++-v3/include/bits/regex.tcc (regex_iterator::operator==(), + regex_iterator::operator++()): Fix operator==() and operator++() to + look at null-ness of _M_pregex on both sides. + * testsuite/28_regex/regression.cc: New testcase. + 2016-11-07 Jason Merrill * include/bits/c++config (_GLIBCXX_NOEXCEPT_PARM) diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index a7d45e6edc4..aadf312cfc0 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -2454,7 +2454,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * one-past-the-end of a range. */ regex_iterator() - : _M_match() + : _M_pregex() { } /** diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc index 4a3d7c36cf8..3f8969d1611 100644 --- a/libstdc++-v3/include/bits/regex.tcc +++ b/libstdc++-v3/include/bits/regex.tcc @@ -496,12 +496,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>:: operator==(const regex_iterator& __rhs) const { - return (_M_match.empty() && __rhs._M_match.empty()) - || (_M_begin == __rhs._M_begin - && _M_end == __rhs._M_end - && _M_pregex == __rhs._M_pregex - && _M_flags == __rhs._M_flags - && _M_match[0] == __rhs._M_match[0]); + if (_M_pregex == nullptr && __rhs._M_pregex == nullptr) + return true; + return _M_pregex == __rhs._M_pregex + && _M_begin == __rhs._M_begin + && _M_end == __rhs._M_end + && _M_flags == __rhs._M_flags + && _M_match[0] == __rhs._M_match[0]; } template r("(f+)"); + { + std::cregex_iterator i(s, s+sizeof(s), r); + std::cregex_iterator j(s, s+sizeof(s), r); + VERIFY(i == j); + } + // The iterator manipulation code must be repeated in the same scope + // to expose the undefined read during the execution of the == + // operator (stack location reuse) + { + std::cregex_iterator i(s, s+sizeof(s), r); + std::cregex_iterator j; + VERIFY(!(i == j)); + } +} + int main() { @@ -80,6 +101,7 @@ main() test03(); test04(); test05(); + test06(); return 0; }