blob: a9eb2b2b94e65dc69b07db64001d7cd74169e029 [file] [log] [blame]
Marshall Clow5a726792017-09-12 17:56:59 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Marshall Clow5a726792017-09-12 17:56:59 +00006//
7//===----------------------------------------------------------------------===//
8
9// <regex>
Marshall Clowbff66aa2017-09-12 23:33:34 +000010// UNSUPPORTED: libcpp-no-exceptions
Roger Ferrer Ibanez5347ebe2017-11-02 15:01:43 +000011// UNSUPPORTED: c++98, c++03
Marshall Clow5a726792017-09-12 17:56:59 +000012
13// template <class BidirectionalIterator, class Allocator, class charT, class traits>
14// bool
15// regex_search(BidirectionalIterator first, BidirectionalIterator last,
16// match_results<BidirectionalIterator, Allocator>& m,
17// const basic_regex<charT, traits>& e,
18// regex_constants::match_flag_type flags = regex_constants::match_default);
19
20// Throw exception after spent too many cycles with respect to the length of the input string.
21
22#include <regex>
23#include <cassert>
Marshall Clowdd426c22019-01-31 18:54:26 +000024#include "test_macros.h"
Marshall Clow5a726792017-09-12 17:56:59 +000025
JF Bastien2df59c52019-02-04 20:31:13 +000026int main(int, char**) {
Marshall Clow5a726792017-09-12 17:56:59 +000027 for (std::regex_constants::syntax_option_type op :
28 {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
29 std::regex::awk}) {
30 try {
Marshall Clowdd426c22019-01-31 18:54:26 +000031 bool b = std::regex_search(
Marshall Clow5a726792017-09-12 17:56:59 +000032 "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));
Marshall Clowdd426c22019-01-31 18:54:26 +000036 LIBCPP_ASSERT(false);
37 assert(b);
Marshall Clow5a726792017-09-12 17:56:59 +000038 } catch (const std::regex_error &e) {
39 assert(e.code() == std::regex_constants::error_complexity);
40 }
41 }
42 std::string s(100000, 'a');
43 for (std::regex_constants::syntax_option_type op :
44 {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
45 std::regex::awk}) {
46 assert(std::regex_search(s, std::regex("a*", op)));
47 }
48 return 0;
49}