https://llvm.org/bugs/show_bug.cgi?id=26175
Bug ID: 26175
Summary: regex does not throw an exception for an ECMAScript
pattern ending in a trailing backslash
Product: libc++
Version: unspecified
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
Created attachment 15643
--> https://llvm.org/bugs/attachment.cgi?id=15643&action=edit
Changes I made to <regex> to produce the behavior I "think" is correct.
When constructing a std::regex object with the pattern "\\" or R"(\)" (that is,
a single backslash), no exception is thrown. I would expect a std::regex_error
to be thrown with the "error_escape" error code, because as far as I have been
able to determine a trailing backslash is not a valid pattern.
I first noticed this in Xcode 7.2 (7C68), compiling with C++14 enabled and the
system libc++ (on OS X 10.11.2). However, I was able to reproduce the issue
using a libc++ built from source (SVN revision 257997).
The following program demonstrates the issue:
#include <iostream>
#include <regex>
int main () {
try {
std::regex example("\\");
} catch (const std::regex_error & error) {
// Never executes, but probably should:
std::cout << "code: " << error.code() << "\n";
}
}
It appears that __parse_atom_escape is the problematic function; it *seems*
that __parse_atom_escape should look something like:
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last && *__first == '\\')
{
_ForwardIterator __t1 = _VSTD::next(__first);
if (__t1 == __last) //!
throw regex_error(regex_constants::error_escape); //!
_ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
...
Where the additional two lines, marked with //!, check if advancing __first has
run in to the end of the expression, and if so throws the appropriate error.
(However my experience in hacking on the standard library is limited to
precisely the above, so I might be very, very off-base with this suggestion.)
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs