1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <regex>
11 // UNSUPPORTED: libcpp-no-exceptions
12 // UNSUPPORTED: c++98, c++03
13 
14 // template <class BidirectionalIterator, class Allocator, class charT, class traits>
15 //     bool
16 //     regex_search(BidirectionalIterator first, BidirectionalIterator last,
17 //                  match_results<BidirectionalIterator, Allocator>& m,
18 //                  const basic_regex<charT, traits>& e,
19 //                  regex_constants::match_flag_type flags = regex_constants::match_default);
20 
21 // Throw exception after spent too many cycles with respect to the length of the input string.
22 
23 #include <regex>
24 #include <cassert>
25 
main()26 int main() {
27   for (std::regex_constants::syntax_option_type op :
28        {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
29         std::regex::awk}) {
30     try {
31       std::regex_search(
32           "aaaaaaaaaaaaaaaaaaaa",
33           std::regex(
34               "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaa",
35               op));
36       assert(false);
37     } catch (const std::regex_error &e) {
38       assert(e.code() == std::regex_constants::error_complexity);
39     }
40   }
41   std::string s(100000, 'a');
42   for (std::regex_constants::syntax_option_type op :
43        {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
44         std::regex::awk}) {
45     assert(std::regex_search(s, std::regex("a*", op)));
46   }
47   return 0;
48 }
49