https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123895

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
When a backref is too large to be represented in an int, we currently throw
this:

        if (__builtin_mul_overflow(__v, __radix, &__v)
            || __builtin_add_overflow(__v, _M_traits.value(__c, __radix),
&__v))
            std::__throw_regex_error(regex_constants::error_backref,
                                     "invalid back reference");

We should consider whether to use error_space for that, but if not then we
should improve the string literal to say that the value was out of range of
int. Otherwise the message for this is quite confusing:

#include <regex>

int main()
{
  std::regex r("a{999999999999}");
}

terminate called after throwing an instance of 'std::regex_error'
  what():  invalid back reference


Invalid why? In a larger regular expression it might not be obvious which back
reference is invalid, and why.

Reply via email to