#include <regex> #include <stdio.h> int main() { std::regex rx("(cat)\\1", std::regex::basic); puts("Constructed without throwing: oops!"); try { std::regex_match("(cat)", rx); } catch (std::exception& e) { puts("regex_match threw instead: oops!"); puts(e.what()); } } The output is: Constructed without throwing: oops! regex_match threw instead: oops! The expression contained an invalid back reference. I claim that the constructor should detect and throw on this pattern, rather than throwing at match time. The same issue happens with the "std::regex::grep" dialect, too.
I had a look at this bug and while investigating I found another bug. Posted the following patches for review. https://reviews.llvm.org/D62451 https://reviews.llvm.org/D62452 https://reviews.llvm.org/D62453