summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-07-23 18:27:51 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-07-23 18:27:51 +0000
commit983d17810811cdac0ff475049451f48a6da5cb25 (patch)
tree76e5899d25d56ed236d56f7fdbec9e25ff69d335 /libcxx/test
parent3f07e7b06363bf88d70bd89b8d45eabf64caf2b3 (diff)
downloadbcm5719-llvm-983d17810811cdac0ff475049451f48a6da5cb25.tar.gz
bcm5719-llvm-983d17810811cdac0ff475049451f48a6da5cb25.zip
Detect and throw on a class of bad regexes that we mistakenly accepted before. Thanks to Trevor Smigiel for the report
llvm-svn: 243030
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp2
-rw-r--r--libcxx/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp42
2 files changed, 43 insertions, 1 deletions
diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
index 9455527412b..ddf2607f112 100644
--- a/libcxx/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ b/libcxx/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -22,7 +22,7 @@ static bool error_escape_thrown(const char *pat)
bool result = false;
try {
std::regex re(pat);
- } catch (std::regex_error &ex) {
+ } catch (const std::regex_error &ex) {
result = (ex.code() == std::regex_constants::error_escape);
}
return result;
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.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// template <class charT, class traits = regex_traits<charT>> class basic_regex;
+
+// template <class ST, class SA>
+// basic_regex(const basic_string<charT, ST, SA>& s);
+
+#include <regex>
+#include <cassert>
+
+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+)"));
+}
OpenPOWER on IntegriCloud