https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102667
Bug ID: 102667 Summary: Inconsistent result of std::regex_match Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program: ``` #include <iostream> #include <string> #include <regex> #include <assert.h> int main() { std::string input("4321"); std::regex rg("^([0-9])"); std::smatch sm; bool found = std::regex_match(input, sm, rg); assert(!sm.size() == sm.empty()); std::cout << "ready: " << sm.ready() << ", found: " << found << ", size: " << sm.size() << std::endl; for (auto it = sm.begin(); it != sm.end(); ++it) { std::cout << "iterate '" << *it << "'\n"; } } ``` prints rather unexpected: ``` ready: 1, found: 0, size: 0 iterate '' iterate '' iterate '' ``` So std::smatch contains 3 entries while its size is zero. Expected result: ``` ready: 1, found: 0, size: 0 ``` Demo: https://gcc.godbolt.org/z/Wfh1vaPqq Related discussion: https://stackoverflow.com/q/66611132/7325599