[libcxx] r185192 - 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

Howard Hinnant hhinnant at apple.com
Fri Jun 28 11:57:30 PDT 2013


Author: hhinnant
Date: Fri Jun 28 13:57:30 2013
New Revision: 185192

URL: http://llvm.org/viewvc/llvm-project?rev=185192&view=rev
Log:
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

Added:
    libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp
Modified:
    libcxx/trunk/include/regex

Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=185192&r1=185191&r2=185192&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Fri Jun 28 13:57:30 2013
@@ -4481,7 +4481,7 @@ basic_regex<_CharT, _Traits>::__parse_ch
                 ++__first;
             }
 #ifndef _LIBCPP_NO_EXCEPTIONS
-            else if (__str)
+            else
                 throw regex_error(regex_constants::error_escape);
 #endif  // _LIBCPP_NO_EXCEPTIONS
             break;

Added: libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp?rev=185192&view=auto
==============================================================================
--- libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp (added)
+++ libcxx/trunk/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp Fri Jun 28 13:57:30 2013
@@ -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);
+    }
+}





More information about the cfe-commits mailing list