https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120212
Bug ID: 120212
Summary: <regex>: Optional empty repetitions should not match
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() {
try {
std::string s{"b"};
std::regex r{"(a*)*"};
std::smatch m;
bool result = std::regex_search(s, m, r);
printf("regex_search: %d\n", result);
for (unsigned i = 0; i < m.size(); ++i) {
printf("m[%d]", i);
if (m[i].matched) {
printf(".str(): \"%s\"\n", m[i].str().c_str());
} else {
puts(".matched: false");
}
}
} catch (const std::exception& e) {
printf("Exception: %s\n", e.what());
}
}
Expected: "" and false, per
https://262.ecma-international.org/5.1/#sec-15.10.2.5 note 4.
Actual: "" and "".
https://godbolt.org/z/s7ejf7GKv
Also present in libc++ and ms-stl
https://github.com/llvm/llvm-project/issues/133314
https://github.com/microsoft/STL/issues/5490