mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 18:38:30 +08:00
[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:
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