<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - regex constructor does not throw an exception for invalid escapes (unless they are in character classes)"
   href="http://llvm.org/bugs/show_bug.cgi?id=16023">16023</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>regex constructor does not throw an exception for invalid escapes (unless they are in character classes)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>william.w.fisher+llvm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=10520" name="attach_10520" title="test case">attachment 10520</a> <a href="attachment.cgi?id=10520&action=edit" title="test case">[details]</a></span>
test case

This code correctly throws a regex_error:

  std::regex char_class_escape("[\\a]");

However, this code does not:

  std::regex escape("\\a");

\a is an invalid escape for ECMAScript so both cases should fail to parse.

This patch fixes the problem in basic_regex::__parse_character_escape:

Index: include/regex
===================================================================
--- include/regex    (revision 181970)
+++ include/regex    (working copy)
@@ -4481,7 +4481,7 @@
                 ++__first;
             }
 #ifndef _LIBCPP_NO_EXCEPTIONS
-            else if (__str)
+            else 
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
             break;</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>