<div dir="ltr">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.<div>
<br></div><div style>My patch uses `__no_update_pos` to communicate when `__at_first` is false.</div><div style><br></div><div><div style>Here is the test case:</div></div><div style><br></div><div style>```</div><div style>
<div>#include <regex></div><div>#include <cassert></div><div><br></div><div>int main()</div><div>{</div><div> // Iterating over /^a/ should yield one instance at the beginning</div><div> // of the text.</div>
<div><br></div><div> const char *text = "aaa\naa";</div><div> std::regex re{"^a"};</div><div> std::cregex_iterator it{text, text+6, re};</div><div> std::cregex_iterator end{};</div><div><br>
</div><div> assert(it->str() == "a");</div><div> assert(it->position(0) == 0);</div><div> assert(it->length(0) == 1);</div><div><br></div><div> ++it;</div><div> assert(it == end);</div><div>
}</div></div><div style>```</div></div>