diff options
author | Tim Shen <timshen@google.com> | 2016-04-23 03:58:37 +0000 |
---|---|---|
committer | Tim Shen <timshen@gcc.gnu.org> | 2016-04-23 03:58:37 +0000 |
commit | 216f7526fef4db4a7f6510f4d48827bb4c55fc64 (patch) | |
tree | 6ff3a147d66e5120aa632460f7333ace19ca6a52 | |
parent | ab0fc037f01de923b69f3c72c717af680ac6066f (diff) | |
download | gcc-216f7526fef4db4a7f6510f4d48827bb4c55fc64.zip gcc-216f7526fef4db4a7f6510f4d48827bb4c55fc64.tar.gz gcc-216f7526fef4db4a7f6510f4d48827bb4c55fc64.tar.bz2 |
re PR libstdc++/70745 (Wrong handling of regex_constant::match_not_eow and regex_constant::match_not_bow)
PR libstdc++/70745
* include/bits/regex_executor.tcc (_Executor<>::_M_word_boundary):
Fix the match_not_bow and match_not_eow behavior.
* testsuite/28_regex/regression.cc: Add testcase.
From-SVN: r235382
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/regex_executor.tcc | 13 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/28_regex/regression.cc | 16 |
3 files changed, 28 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e6934a5..386e832 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2016-04-22 Tim Shen <timshen@google.com> + + PR libstdc++/70745 + * include/bits/regex_executor.tcc (_Executor<>::_M_word_boundary): + Fix the match_not_bow and match_not_eow behavior. + * testsuite/28_regex/regression.cc: Add testcase. + 2016-04-20 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/69703 diff --git a/libstdc++-v3/include/bits/regex_executor.tcc b/libstdc++-v3/include/bits/regex_executor.tcc index 2abd020..6bbcb1b 100644 --- a/libstdc++-v3/include/bits/regex_executor.tcc +++ b/libstdc++-v3/include/bits/regex_executor.tcc @@ -413,6 +413,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>:: _M_word_boundary() const { + if (_M_current == _M_begin && (_M_flags & regex_constants::match_not_bow)) + return false; + if (_M_current == _M_end && (_M_flags & regex_constants::match_not_eow)) + return false; + bool __left_is_word = false; if (_M_current != _M_begin || (_M_flags & regex_constants::match_prev_avail)) @@ -424,13 +429,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool __right_is_word = _M_current != _M_end && _M_is_word(*_M_current); - if (__left_is_word == __right_is_word) - return false; - if (__left_is_word && !(_M_flags & regex_constants::match_not_eow)) - return true; - if (__right_is_word && !(_M_flags & regex_constants::match_not_bow)) - return true; - return false; + return __left_is_word != __right_is_word; } _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/28_regex/regression.cc b/libstdc++-v3/testsuite/28_regex/regression.cc index c9a3402..d367c8b 100644 --- a/libstdc++-v3/testsuite/28_regex/regression.cc +++ b/libstdc++-v3/testsuite/28_regex/regression.cc @@ -45,7 +45,20 @@ test02() "/ghci" }; auto rx = std::regex(re_str, std::regex_constants::grep | std::regex_constants::icase); - VERIFY(std::regex_search("/abcd", rx)); + VERIFY(regex_search_debug("/abcd", rx)); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + VERIFY(regex_match_debug("a.", regex(R"(a\b.)"), regex_constants::match_not_eow)); + VERIFY(regex_match_debug(".a", regex(R"(.\ba)"), regex_constants::match_not_bow)); + VERIFY(regex_search_debug("a", regex(R"(^\b)"))); + VERIFY(regex_search_debug("a", regex(R"(\b$)"))); + VERIFY(!regex_search_debug("a", regex(R"(^\b)"), regex_constants::match_not_bow)); + VERIFY(!regex_search_debug("a", regex(R"(\b$)"), regex_constants::match_not_eow)); } int @@ -53,6 +66,7 @@ main() { test01(); test02(); + test03(); return 0; } |