blob: c48cc94d1488dab2d88c9efcb6be43f262e40fcd [file] [log] [blame]
Marshall Clow5a726792017-09-12 17:56:59 +00001//===----------------------------------------------------------------------===//
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
12// template <class BidirectionalIterator, class Allocator, class charT, class traits>
13// bool
14// regex_search(BidirectionalIterator first, BidirectionalIterator last,
15// match_results<BidirectionalIterator, Allocator>& m,
16// const basic_regex<charT, traits>& e,
17// regex_constants::match_flag_type flags = regex_constants::match_default);
18
19// Throw exception after spent too many cycles with respect to the length of the input string.
20
21#include <regex>
22#include <cassert>
23
24int main() {
25 for (std::regex_constants::syntax_option_type op :
26 {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
27 std::regex::awk}) {
28 try {
29 std::regex_search(
30 "aaaaaaaaaaaaaaaaaaaa",
31 std::regex(
32 "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaa",
33 op));
34 assert(false);
35 } catch (const std::regex_error &e) {
36 assert(e.code() == std::regex_constants::error_complexity);
37 }
38 }
39 std::string s(100000, 'a');
40 for (std::regex_constants::syntax_option_type op :
41 {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
42 std::regex::awk}) {
43 assert(std::regex_search(s, std::regex("a*", op)));
44 }
45 return 0;
46}