[PATCH] D42291: [libcxx] Correctly handle invalid regex character class names
Mikhail Maltsev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 19 03:53:52 PST 2018
miyuki created this revision.
miyuki added reviewers: EricWF, mclow.lists.
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.
https://reviews.llvm.org/D42291
Files:
include/regex
test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
Index: test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
===================================================================
--- /dev/null
+++ 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:]]"));
+}
Index: include/regex
===================================================================
--- include/regex
+++ include/regex
@@ -4013,7 +4013,7 @@
char_class_type __class_type =
__traits_.lookup_classname(__first, __temp, __flags_ & icase);
if (__class_type == 0)
- __throw_regex_error<regex_constants::error_brack>();
+ __throw_regex_error<regex_constants::error_ctype>();
__ml->__add_class(__class_type);
__first = _VSTD::next(__temp, 2);
return __first;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42291.130584.patch
Type: text/x-patch
Size: 1766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180119/7dca1ac7/attachment.bin>
More information about the cfe-commits
mailing list