[PATCH] D16262: [libc++] Treat trailing backslashes in a regex pattern as invalid.

2016-01-18 Thread Josh Petrie via cfe-commits
jpetrie created this revision.
jpetrie added a reviewer: mclow.lists.
jpetrie added a subscriber: cfe-commits.

std::regex should throw std::regex_error if constructed with a pattern ending 
in a trailing backslash, since a trailing backlash is not a valid escape 
sequence.

http://reviews.llvm.org/D16262

Files:
  include/regex
  test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp

Index: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
===
--- test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -33,6 +33,7 @@
 {
 assert(error_escape_thrown("[\\a]"));
 assert(error_escape_thrown("\\a"));
+assert(error_escape_thrown("\\"));
 
 assert(error_escape_thrown("[\\e]"));
 assert(error_escape_thrown("\\e"));
Index: include/regex
===
--- include/regex
+++ include/regex
@@ -4265,6 +4265,9 @@
 if (__first != __last && *__first == '\\')
 {
 _ForwardIterator __t1 = _VSTD::next(__first);
+if (__t1 == __last)
+__throw_regex_error();
+
 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
 if (__t2 != __t1)
 __first = __t2;


Index: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
===
--- test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -33,6 +33,7 @@
 {
 assert(error_escape_thrown("[\\a]"));
 assert(error_escape_thrown("\\a"));
+assert(error_escape_thrown("\\"));
 
 assert(error_escape_thrown("[\\e]"));
 assert(error_escape_thrown("\\e"));
Index: include/regex
===
--- include/regex
+++ include/regex
@@ -4265,6 +4265,9 @@
 if (__first != __last && *__first == '\\')
 {
 _ForwardIterator __t1 = _VSTD::next(__first);
+if (__t1 == __last)
+__throw_regex_error();
+
 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
 if (__t2 != __t1)
 __first = __t2;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16262: [libc++] Treat trailing backslashes in a regex pattern as invalid.

2016-01-19 Thread Josh Petrie via cfe-commits
jpetrie added a comment.

In http://reviews.llvm.org/D16262#329328, @mclow.lists wrote:

> This looks good to me.  A quick search for `\\` in regex didn't find any 
> other obvious instances of this anti-pattern.  For the record, the bug is 
> https://llvm.org/bugs/show_bug.cgi?id=26175
>
> Can you commit this yourself, or would you rather I did it?


I don't have commit access; if you could commit it, that would be great.


http://reviews.llvm.org/D16262



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits