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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We could also make it scale with the target word size:

      const size_t __dist = std::distance(_M_begin, _M_end);
      constexpr unsigned __scale = __SIZE_WIDTH__ / 5 + 1;
      unsigned __steps = 0;

      while (!_M_frames.empty())
        {
          ++__steps;
          if ((__steps >> __scale) > __dist)
            __throw_regex_error(regex_constants::error_complexity,
                                "it's over 9000!");

This would allow higher complexity on 64-bit targets than on 32-bit or smaller.

Or instead of __SIZE_WIDTH__ / 5 we could just hardcode values:

#if __SIZE_WIDTH__ >= 64
  constexpr unsigned __scale = ...
#elif __SIZE_WIDTH__ >= 32
  ...

We could also allow users to override it with a macro.

Reply via email to