summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/re
diff options
context:
space:
mode:
authorMikhail Maltsev <mikhail.maltsev@arm.com>2018-01-24 12:45:18 +0000
committerMikhail Maltsev <mikhail.maltsev@arm.com>2018-01-24 12:45:18 +0000
commit48c63d879b4a3a84f4dd21256b4a3d29037055c8 (patch)
treed3925b971f0c083c6abac4a4cd2fcf8a678a62b9 /libcxx/test/std/re
parente4453233d78788989c4bf2ff927a9e67433fb63d (diff)
downloadbcm5719-llvm-48c63d879b4a3a84f4dd21256b4a3d29037055c8.tar.gz
bcm5719-llvm-48c63d879b4a3a84f4dd21256b4a3d29037055c8.zip
[libcxx] Correctly handle invalid regex character class names
Summary: Currently when a regular expression contains an invalid character class name std::regex constructors throw an std::regex_error with std::regex_constants::error_brack code. This patch changes the code to std::regex_constants::error_ctype and adds a test. Reviewers: EricWF, mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42291 llvm-svn: 323322
Diffstat (limited to 'libcxx/test/std/re')
-rw-r--r--libcxx/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
new file mode 100644
index 00000000000..aa70258dbfa
--- /dev/null
+++ b/libcxx/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: libcpp-no-exceptions
+// <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>
+#include "test_macros.h"
+
+static bool error_ctype_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_ctype);
+ }
+ return result;
+}
+
+int main()
+{
+ assert(error_ctype_thrown("[[::]]"));
+ assert(error_ctype_thrown("[[:error:]]"));
+}
OpenPOWER on IntegriCloud