[libcxx-commits] [PATCH] D61828: Throw the proper exception on a regex range error
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 11 12:45:36 PDT 2019
Mordante created this revision.
Mordante added a reviewer: mclow.lists.
Mordante added a project: libc++.
Herald added a subscriber: christof.
While looking at bug 39575 <https://bugs.llvm.org/show_bug.cgi?id=39575> I noticed the wrong exception was thrown. This fixes the exception thrown and adds a unit test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D61828
Files:
libcxx/include/regex
libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
Index: libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// 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_range_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_range);
+ }
+ return result;
+}
+
+int main(int, char**)
+{
+ assert(error_range_thrown(R"([\w-a])"));
+ assert(error_range_thrown(R"([a-\w])"));
+
+ return 0;
+}
Index: libcxx/include/regex
===================================================================
--- libcxx/include/regex
+++ libcxx/include/regex
@@ -2306,7 +2306,7 @@
else
{
if (__b.size() != 1 || __e.size() != 1)
- __throw_regex_error<regex_constants::error_collate>();
+ __throw_regex_error<regex_constants::error_range>();
if (__icase_)
{
__b[0] = __traits_.translate_nocase(__b[0]);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61828.199154.patch
Type: text/x-patch
Size: 1838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190511/a9f83a4e/attachment.bin>
More information about the libcxx-commits
mailing list