summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/regex11
-rw-r--r--libcxx/test/re/re.regex/re.regex.construct/bad_escape.pass.cpp32
2 files changed, 30 insertions, 13 deletions
diff --git a/libcxx/include/regex b/libcxx/include/regex
index 19e08b13aaf..3ec2ff92ee0 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -4418,7 +4418,8 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
case 'c':
if ((__t = _VSTD::next(__first)) != __last)
{
- if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
+ if (('A' <= *__t && *__t <= 'Z') ||
+ ('a' <= *__t && *__t <= 'z'))
{
if (__str)
*__str = _CharT(*__t % 32);
@@ -4426,7 +4427,15 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
__push_char(_CharT(*__t % 32));
__first = ++__t;
}
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ else
+ throw regex_error(regex_constants::error_escape);
+#endif // _LIBCPP_NO_EXCEPTIONS
}
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ else
+ throw regex_error(regex_constants::error_escape);
+#endif // _LIBCPP_NO_EXCEPTIONS
break;
case 'u':
++__first;
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);
- }
}
OpenPOWER on IntegriCloud