[libcxx] r323322 - [libcxx] Correctly handle invalid regex character class names
Mikhail Maltsev via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 24 04:45:18 PST 2018
Author: miyuki
Date: Wed Jan 24 04:45:18 2018
New Revision: 323322
URL: http://llvm.org/viewvc/llvm-project?rev=323322&view=rev
Log:
[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
Added:
libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
Modified:
libcxx/trunk/include/regex
Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=323322&r1=323321&r2=323322&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Wed Jan 24 04:45:18 2018
@@ -4013,7 +4013,7 @@ basic_regex<_CharT, _Traits>::__parse_ch
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;
Added: libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp?rev=323322&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp Wed Jan 24 04:45:18 2018
@@ -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:]]"));
+}
More information about the cfe-commits
mailing list