From 983d17810811cdac0ff475049451f48a6da5cb25 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 23 Jul 2015 18:27:51 +0000 Subject: Detect and throw on a class of bad regexes that we mistakenly accepted before. Thanks to Trevor Smigiel for the report llvm-svn: 243030 --- .../re.regex.construct/bad_repeat.pass.cpp | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp (limited to 'libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp') diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp new file mode 100644 index 00000000000..bc70ec1302d --- /dev/null +++ b/libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// template > class basic_regex; + +// template +// basic_regex(const basic_string& s); + +#include +#include + +static bool error_badrepeat_thrown(const char *pat) +{ + bool result = false; + try { + std::regex re(pat); + } catch (const std::regex_error &ex) { + result = (ex.code() == std::regex_constants::error_badrepeat); + } + return result; +} + +int main() +{ + assert(error_badrepeat_thrown("?a")); + assert(error_badrepeat_thrown("*a")); + assert(error_badrepeat_thrown("+a")); + assert(error_badrepeat_thrown("{a")); + + assert(error_badrepeat_thrown("?(a+)")); + assert(error_badrepeat_thrown("*(a+)")); + assert(error_badrepeat_thrown("+(a+)")); + assert(error_badrepeat_thrown("{(a+)")); +} -- cgit v1.2.3