15a726793SMarshall Clow //===----------------------------------------------------------------------===//
25a726793SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a726793SMarshall Clow //
75a726793SMarshall Clow //===----------------------------------------------------------------------===//
85a726793SMarshall Clow
95a726793SMarshall Clow // <regex>
108c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
11*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03
125a726793SMarshall Clow
135a726793SMarshall Clow // template <class BidirectionalIterator, class Allocator, class charT, class traits>
145a726793SMarshall Clow // bool
155a726793SMarshall Clow // regex_search(BidirectionalIterator first, BidirectionalIterator last,
165a726793SMarshall Clow // match_results<BidirectionalIterator, Allocator>& m,
175a726793SMarshall Clow // const basic_regex<charT, traits>& e,
185a726793SMarshall Clow // regex_constants::match_flag_type flags = regex_constants::match_default);
195a726793SMarshall Clow
205a726793SMarshall Clow // Throw exception after spent too many cycles with respect to the length of the input string.
215a726793SMarshall Clow
225a726793SMarshall Clow #include <regex>
235a726793SMarshall Clow #include <cassert>
24dd426c2fSMarshall Clow #include "test_macros.h"
255a726793SMarshall Clow
main(int,char **)262df59c50SJF Bastien int main(int, char**) {
275a726793SMarshall Clow for (std::regex_constants::syntax_option_type op :
285a726793SMarshall Clow {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
295a726793SMarshall Clow std::regex::awk}) {
305a726793SMarshall Clow try {
31dd426c2fSMarshall Clow bool b = std::regex_search(
325a726793SMarshall Clow "aaaaaaaaaaaaaaaaaaaa",
335a726793SMarshall Clow std::regex(
345a726793SMarshall Clow "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaa",
355a726793SMarshall Clow op));
36dd426c2fSMarshall Clow LIBCPP_ASSERT(false);
37dd426c2fSMarshall Clow assert(b);
385a726793SMarshall Clow } catch (const std::regex_error &e) {
395a726793SMarshall Clow assert(e.code() == std::regex_constants::error_complexity);
405a726793SMarshall Clow }
415a726793SMarshall Clow }
425a726793SMarshall Clow std::string s(100000, 'a');
435a726793SMarshall Clow for (std::regex_constants::syntax_option_type op :
445a726793SMarshall Clow {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
455a726793SMarshall Clow std::regex::awk}) {
465a726793SMarshall Clow assert(std::regex_search(s, std::regex("a*", op)));
475a726793SMarshall Clow }
485a726793SMarshall Clow return 0;
495a726793SMarshall Clow }
50