[libc++][regex] Validate backreferences in the constructor.
This patch enables throwing exceptions for invalid backreferences
in the constructor when using the basic, extended, grep, or egrep grammar.
This fixes bug 34297.
Differential Revision: https://reviews.llvm.org/D62453
Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 72ce0c8073bc8dfa109d25a3c5f245ee0285568c
diff --git a/include/regex b/include/regex
index e349fa6..68cfbb2 100644
--- a/include/regex
+++ b/include/regex
@@ -4661,6 +4661,8 @@
unsigned __val = __traits_.value(c, 10);
if (__val >= 1 && __val <= 9)
{
+ if (__val > mark_count())
+ __throw_regex_error<regex_constants::error_backref>();
__push_back_ref(__val);
return true;
}