[PATCH][libcxx] regex_iterator needs to handle /^a/ anchor correctly

William Fisher william.w.fisher at gmail.com
Mon Jul 8 20:13:29 PDT 2013


This patch fixes a bug where regex_iterator doesn't indicate when it's
restarting in the middle of a string. This bug causes /^a/ to match in the
middle of the string "aaaaaaa", during iteration.

My patch uses `__no_update_pos` to communicate when `__at_first` is false.

Here is the test case:

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

int main()
{
    // Iterating over /^a/ should yield one instance at the beginning
    // of the text.

    const char *text = "aaa\naa";
    std::regex re{"^a"};
    std::cregex_iterator it{text, text+6, re};
    std::cregex_iterator end{};

    assert(it->str() == "a");
    assert(it->position(0) == 0);
    assert(it->length(0) == 1);

    ++it;
    assert(it == end);
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130708/48f0cfd3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: regex_iter.patch
Type: application/octet-stream
Size: 654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130708/48f0cfd3/attachment.obj>


More information about the cfe-commits mailing list