diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2017-09-12 17:56:59 +0000 | 
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2017-09-12 17:56:59 +0000 | 
| commit | 5a72679338f9dc0e38c98befe65aac73de1822ab (patch) | |
| tree | f557c6358713889624e6c472e8d04cfac5ba62de /libcxx/test/std/re/re.alg/re.alg.search/exponential.pass.cpp | |
| parent | 06ff655e591bc8cf2bcdc0358c49f8872b0f3a0e (diff) | |
| download | bcm5719-llvm-5a72679338f9dc0e38c98befe65aac73de1822ab.tar.gz bcm5719-llvm-5a72679338f9dc0e38c98befe65aac73de1822ab.zip  | |
Apply D28224: 'Throw exception after too many steps' Fixes PR#20291. Thanks to Tim Shen for the patch
llvm-svn: 313056
Diffstat (limited to 'libcxx/test/std/re/re.alg/re.alg.search/exponential.pass.cpp')
| -rw-r--r-- | libcxx/test/std/re/re.alg/re.alg.search/exponential.pass.cpp | 46 | 
1 files changed, 46 insertions, 0 deletions
diff --git a/libcxx/test/std/re/re.alg/re.alg.search/exponential.pass.cpp b/libcxx/test/std/re/re.alg/re.alg.search/exponential.pass.cpp new file mode 100644 index 00000000000..c48cc94d148 --- /dev/null +++ b/libcxx/test/std/re/re.alg/re.alg.search/exponential.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// template <class BidirectionalIterator, class Allocator, class charT, class traits> +//     bool +//     regex_search(BidirectionalIterator first, BidirectionalIterator last, +//                  match_results<BidirectionalIterator, Allocator>& m, +//                  const basic_regex<charT, traits>& e, +//                  regex_constants::match_flag_type flags = regex_constants::match_default); + +// Throw exception after spent too many cycles with respect to the length of the input string. + +#include <regex> +#include <cassert> + +int main() { +  for (std::regex_constants::syntax_option_type op : +       {std::regex::ECMAScript, std::regex::extended, std::regex::egrep, +        std::regex::awk}) { +    try { +      std::regex_search( +          "aaaaaaaaaaaaaaaaaaaa", +          std::regex( +              "a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaa", +              op)); +      assert(false); +    } catch (const std::regex_error &e) { +      assert(e.code() == std::regex_constants::error_complexity); +    } +  } +  std::string s(100000, 'a'); +  for (std::regex_constants::syntax_option_type op : +       {std::regex::ECMAScript, std::regex::extended, std::regex::egrep, +        std::regex::awk}) { +    assert(std::regex_search(s, std::regex("a*", op))); +  } +  return 0; +}  | 

