blob: f7a6f91efe0489b950158b663edaaf9ba6f7f90a [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>
Marshall Clowbff66aa2017-09-12 23:33:34 +000011// UNSUPPORTED: libcpp-no-exceptions
Roger Ferrer Ibanez5347ebe2017-11-02 15:01:43 +000012// UNSUPPORTED: c++98, c++03
Marshall Clow5a726792017-09-12 17:56:59 +000013
14// template <class BidirectionalIterator, class Allocator, class charT, class traits>
15// bool
16// regex_match(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
26int 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_match(
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_match(s, std::regex("a*", op)));
46 }
47 return 0;
48}