https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111129
Bug ID: 111129 Summary: std::regex incorrectly matches quantifiers with plus appended Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc at octaforge dot org Target Milestone: --- Example code: ``` #include <cstdio> #include <string> #include <regex> int main(void) { std::smatch matches; auto re = std::regex(R"(a++)", std::regex::icase); std::string inp = "aaa"; std::regex_search(inp, matches, re); for (auto &match: matches) { printf("%s\n", match.str().data()); } } ``` With libstdc++, this does not crash, and outputs 'aaa'. This gives people a false idea that libstdc++ implements possessive quantifiers (see e.g. https://github.com/wwmm/easyeffects/pull/2536) despite the documentation or code having no references to any such extension (and the C++ standard likewise not mentioning it). You can verify that the semantics are not possessive by changing the pattern to 'a++a', which should with possessive semantics not match anything, but with libstdc++ it's an identical match as before. With libc++, this correctly fails with: libc++abi: terminating due to uncaught exception of type std::__1::regex_error: One of *?+{ was not preceded by a valid regular expression.