Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <regex> |
| 11 | |
| 12 | // template <class charT, class traits = regex_traits<charT>> class basic_regex; |
| 13 | |
| 14 | // template <class ST, class SA> |
| 15 | // basic_regex(const basic_string<charT, ST, SA>& s); |
| 16 | |
| 17 | #include <regex> |
| 18 | #include <cassert> |
| 19 | |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 20 | static bool error_escape_thrown(const char *pat) |
| 21 | { |
| 22 | bool result = false; |
| 23 | try { |
| 24 | std::regex re(pat); |
Marshall Clow | 568bd02 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 25 | } catch (const std::regex_error &ex) { |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 26 | result = (ex.code() == std::regex_constants::error_escape); |
| 27 | } |
| 28 | return result; |
| 29 | } |
| 30 | |
Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 31 | int main() |
| 32 | { |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 33 | assert(error_escape_thrown("[\\a]")); |
| 34 | assert(error_escape_thrown("\\a")); |
Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 35 | |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 36 | assert(error_escape_thrown("[\\e]")); |
| 37 | assert(error_escape_thrown("\\e")); |
| 38 | |
| 39 | assert(error_escape_thrown("[\\c:]")); |
| 40 | assert(error_escape_thrown("\\c:")); |
| 41 | assert(error_escape_thrown("\\c")); |
| 42 | assert(!error_escape_thrown("[\\cA]")); |
| 43 | assert(!error_escape_thrown("\\cA")); |
| 44 | |
Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 45 | } |