diff options
author | Howard Hinnant <hhinnant@apple.com> | 2013-07-15 18:21:11 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2013-07-15 18:21:11 +0000 |
commit | 22161401df1fe5f3eb57f099e8bca065822549df (patch) | |
tree | d4c85cedc0aa88fabafedc1085192ca7424da144 /libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp | |
parent | 10f8387b9430099bd5dc43db860ade8d165d8d94 (diff) | |
download | bcm5719-llvm-22161401df1fe5f3eb57f099e8bca065822549df.tar.gz bcm5719-llvm-22161401df1fe5f3eb57f099e8bca065822549df.zip |
Bill Fisher: This patch fixes an ill-formed comparison when parsing control escapes, e.g. "\cA\ca". The code will now throw an error_escape exception for invalid control sequences like "\c:" or "\c".
I've added the test cases to bad_escape.pass.cpp.
llvm-svn: 186335
Diffstat (limited to 'libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp')
-rw-r--r-- | libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp b/libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp index 75845a232c4..9455527412b 100644 --- a/libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp +++ b/libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp @@ -17,21 +17,29 @@ #include <regex> #include <cassert> -int main() +static bool error_escape_thrown(const char *pat) { - // Correct: Exception thrown for invalid escape char in a character class + bool result = false; try { - std::regex char_class_escape("[\\a]"); - assert(false); + std::regex re(pat); } catch (std::regex_error &ex) { - assert(ex.code() == std::regex_constants::error_escape); + result = (ex.code() == std::regex_constants::error_escape); } + return result; +} + +int main() +{ + assert(error_escape_thrown("[\\a]")); + assert(error_escape_thrown("\\a")); + + assert(error_escape_thrown("[\\e]")); + assert(error_escape_thrown("\\e")); + + assert(error_escape_thrown("[\\c:]")); + assert(error_escape_thrown("\\c:")); + assert(error_escape_thrown("\\c")); + assert(!error_escape_thrown("[\\cA]")); + assert(!error_escape_thrown("\\cA")); - // 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); - } } |