* 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.
(cherry-picked from commit
566d49d6947f4590609562dd5f33d0e6b24a4267)
Change-Id: Ie38f6f857575432c90f9ae17576ddff4c7bc021a
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235382
138bc75d-0d04-0410-961f-
82ee72b054a4
+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.
+
2017-02-01 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/78346
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))
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
"/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
{
test01();
test02();
+ test03();
return 0;
}