[llvm-bugs] [Bug 26175] New: regex does not throw an exception for an ECMAScript pattern ending in a trailing backslash
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jan 16 10:29:18 PST 2016
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: unassignedclangbugs at nondot.org
Reporter: josh.petrie at gmail.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160116/db0d38f1/attachment-0001.html>
More information about the llvm-bugs
mailing list