Skip to content

Commit 8badd8a

Browse files
[libc++] Fix regex_search to match $ alone with match_default flag
1 parent 360996a commit 8badd8a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

libcxx/include/regex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,9 @@ void __r_anchor_multiline<_CharT>::__exec(__state& __s) const {
18891889
if (__s.__current_ == __s.__last_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
18901890
__s.__do_ = __state::__accept_but_not_consume;
18911891
__s.__node_ = this->first();
1892+
} else if (__s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
1893+
__s.__do_ = __state::__accept_but_not_consume;
1894+
__s.__node_ = this->first();
18921895
} else if (__multiline_ && std::__is_eol(*__s.__current_)) {
18931896
__s.__do_ = __state::__accept_but_not_consume;
18941897
__s.__node_ = this->first();

libcxx/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,19 @@ int main(int, char**)
4747
assert( std::regex_search(target, re, std::regex_constants::match_not_eol));
4848
}
4949

50+
{
51+
std::string target = "foo";
52+
std::regex re("$");
53+
assert(std::regex_search(target, re));
54+
assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));
55+
}
56+
57+
{
58+
std::string target = "foo";
59+
std::regex re("$");
60+
assert(!std::regex_match(target, re));
61+
assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));
62+
}
63+
5064
return 0;
5165
}

0 commit comments

Comments
 (0)