[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 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323322 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -4013,7 +4013,7 @@ basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
|
||||
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;
|
||||
|
||||
37
test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
Normal file
37
test/std/re/re.regex/re.regex.construct/bad_ctype.pass.cpp
Normal file
@@ -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:]]"));
|
||||
}
|
||||
Reference in New Issue
Block a user