https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119505
Bug ID: 119505 Summary: <regex>: Undefined backreferences should match empty string Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: blubban at gmail dot com Target Milestone: --- #include <regex> #include <stdio.h> int main() { std::string s{"a"}; std::regex r{"(b)?\\1"}; std::smatch m; bool result = std::regex_search(s, m, r); printf("search=%d\n", result); } Expected: Return true, because the capture group fails to match and is skipped, and the backreference then matches the empty string, per https://262.ecma-international.org/5.1/#sec-15.10.2.9 5.3. Actual: Returns false. https://godbolt.org/z/5v8Yjqnd6 libc++ has the same bug. https://github.com/llvm/llvm-project/issues/133360