Bill Fisher: Fix for failing to throw an exception in regex when parsing an invalid escape sequence. This fixes http://llvm.org/bugs/show_bug.cgi?id=16023
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185192 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b9d9fb4a17
commit
918f2a80ab
@ -4481,7 +4481,7 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
|
|||||||
++__first;
|
++__first;
|
||||||
}
|
}
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
else if (__str)
|
else
|
||||||
throw regex_error(regex_constants::error_escape);
|
throw regex_error(regex_constants::error_escape);
|
||||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||||
break;
|
break;
|
||||||
|
37
test/re/re.regex/re.regex.construct/bad_escape.pass.cpp
Normal file
37
test/re/re.regex/re.regex.construct/bad_escape.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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <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>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Correct: Exception thrown for invalid escape char in a character class
|
||||||
|
try {
|
||||||
|
std::regex char_class_escape("[\\a]");
|
||||||
|
assert(false);
|
||||||
|
} catch (std::regex_error &ex) {
|
||||||
|
assert(ex.code() == std::regex_constants::error_escape);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failure: No exception thrown for invalid escape char in this case.
|
||||||
|
try {
|
||||||
|
std::regex escape("\\a");
|
||||||
|
assert(false);
|
||||||
|
} catch (std::regex_error &ex) {
|
||||||
|
assert(ex.code() == std::regex_constants::error_escape);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user