This patch addresses http://llvm.org/bugs/show_bug.cgi?id=11118

A bug in __lookahead::exec causes /(?=^)b/ to match "ab". When
`__lookahead::__exec` makes a recursive call to
`__exp_.__match_at_start_ecma`, it passes true for the value of
`__at_first`. This causes a beginning-of-line anchor (^) inside a lookahead
assertion to match anywhere in the text.

Here is a test case (before the patch, both asserts fail).

```
#include <regex>
#include <cassert>

int main()
{
    assert(!std::regex_search("ab", std::regex("(?=^)b")));
    assert(!std::regex_search("ab", std::regex("a(?=^)b")));
}
```
Index: include/regex
===================================================================
--- include/regex       (revision 182628)
+++ include/regex       (working copy)
@@ -2921,7 +2921,7 @@
     bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
                                                   __m,
                                                   __s.__flags_ | 
regex_constants::match_continuous,
-                                                  true);
+                                                  __s.__at_first_ && 
__s.__current_ == __s.__first_);
     if (__matched != __invert_)
     {
         __s.__do_ = __state::__accept_but_not_consume;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to