-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Fix regex_search
to match $
alone with match_default
flag
#77256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libcxx Author: Sanjay Marreddi (SanjayMarreddi) ChangesUsing Fixes #75042 Full diff: https://github.com/llvm/llvm-project/pull/77256.diff 2 Files Affected:
diff --git a/libcxx/include/regex b/libcxx/include/regex
index b575a267583b5f..0761d9de54a95c 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -1889,6 +1889,9 @@ void __r_anchor_multiline<_CharT>::__exec(__state& __s) const {
if (__s.__current_ == __s.__last_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
+ } else if (__s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
+ __s.__do_ = __state::__accept_but_not_consume;
+ __s.__node_ = this->first();
} else if (__multiline_ && std::__is_eol(*__s.__current_)) {
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
diff --git a/libcxx/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp b/libcxx/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp
index edeea517d2537a..76f8986b2d539f 100644
--- a/libcxx/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp
+++ b/libcxx/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp
@@ -47,5 +47,12 @@ int main(int, char**)
assert( std::regex_search(target, re, std::regex_constants::match_not_eol));
}
+ {
+ std::string target = "foo";
+ std::regex re("$");
+ assert(std::regex_search(target, re));
+ assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));
+ }
+
return 0;
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks looks good, I'd like one more test before approval.
bbc98d9
to
1412a7c
Compare
1412a7c
to
8badd8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM! Do you need assistance to land this patch?
I'm sorry, I don't think I fully understood what you asked. If you have asked, if I need assistance to get this merged, yes!! |
Yes it was about merging. Before we used Phabricator and used the word landing. |
Now, I get it :) Thanks!! |
It looks like the patch changes the behavior of search for patterns anchored both to the start and to the end of the input, e.g. after this change The behavior is now different to that of libstdc++: https://gcc.godbolt.org/z/hcd4acrb6
returns 1 on libc++ and 0 on libstdc++ (and libc++ before this change). |
@alexfh Thanks much for letting us know about this. I will look into it. |
As usual: if the behavior is not intended (which I suspect is true) and there's no obvious and reliable fix, I'd suggest to revert first. |
This seems broken to me -- the pattern |
I have created the revert. Will add this test case and work on relanding the patch. |
…fault` flag" (llvm#78349) The behavior of `std::regex_search` for patterns anchored both to the start and to the end of the input went wrong after merging llvm#77256 . Patterns like `"^b*$"` started matching the strings such as `"a"`, which is not expected. Reverts the PR: llvm#77256
I have fixed the above test case along with the |
…lag (llvm#77256) Using `regex_search` with the regex_constant `match_default` and a simple regex pattern `$` is expected to match general strings such as _"a", "ab", "abc"..._ at `[last, last)` positions. But, the current implementation fails to do so. Fixes llvm#75042
Using
regex_search
with the regex_constantmatch_default
and a simple regex pattern$
is expected to match general strings such as "a", "ab", "abc"... at[last, last)
positions. But, the current implementation fails to do so.Fixes #75042