50 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <regex>10// UNSUPPORTED: no-exceptions11// UNSUPPORTED: c++0312 13// template <class BidirectionalIterator, class Allocator, class charT, class traits>14// bool15// 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>24#include "test_macros.h"25 26int main(int, char**) {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 bool b = 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 LIBCPP_ASSERT(false);37 assert(b);38 } 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}50