Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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-exception |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <regex> |
Marshall Clow | bff66aa | 2017-09-12 23:33:34 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: libcpp-no-exceptions |
Roger Ferrer Ibanez | 5347ebe | 2017-11-02 15:01:43 +0000 | [diff] [blame] | 11 | // UNSUPPORTED: c++98, c++03 |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 12 | |
| 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 Clow | dd426c2 | 2019-01-31 18:54:26 +0000 | [diff] [blame] | 24 | #include "test_macros.h" |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 25 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 26 | int main(int, char**) { |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 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 { |
Marshall Clow | dd426c2 | 2019-01-31 18:54:26 +0000 | [diff] [blame] | 31 | bool b = std::regex_search( |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 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)); |
Marshall Clow | dd426c2 | 2019-01-31 18:54:26 +0000 | [diff] [blame] | 36 | LIBCPP_ASSERT(false); |
| 37 | assert(b); |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 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 | } |