exponential.pass.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <regex>
  9. // UNSUPPORTED: libcpp-no-exceptions
  10. // UNSUPPORTED: c++98, c++03
  11. // template <class BidirectionalIterator, class Allocator, class charT, class traits>
  12. // bool
  13. // regex_match(BidirectionalIterator first, BidirectionalIterator last,
  14. // match_results<BidirectionalIterator, Allocator>& m,
  15. // const basic_regex<charT, traits>& e,
  16. // regex_constants::match_flag_type flags = regex_constants::match_default);
  17. // Throw exception after spent too many cycles with respect to the length of the input string.
  18. #include <regex>
  19. #include <cassert>
  20. #include "test_macros.h"
  21. int main(int, char**) {
  22. for (std::regex_constants::syntax_option_type op :
  23. {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
  24. std::regex::awk}) {
  25. try {
  26. bool b = std::regex_match(
  27. "aaaaaaaaaaaaaaaaaaaa",
  28. std::regex(
  29. "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaa",
  30. op));
  31. LIBCPP_ASSERT(false);
  32. assert(b);
  33. } catch (const std::regex_error &e) {
  34. assert(e.code() == std::regex_constants::error_complexity);
  35. }
  36. }
  37. std::string s(100000, 'a');
  38. for (std::regex_constants::syntax_option_type op :
  39. {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
  40. std::regex::awk}) {
  41. assert(std::regex_match(s, std::regex("a*", op)));
  42. }
  43. return 0;
  44. }