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 // XFAIL: libcpp-no-exceptions 11 // <regex> 12 13 // template <class charT, class traits = regex_traits<charT>> class basic_regex; 14 15 // template <class ST, class SA> 16 // basic_regex(const basic_string<charT, ST, SA>& s); 17 18 #include <regex> 19 #include <cassert> 20 21 static bool error_escape_thrown(const char *pat) 22 { 23 bool result = false; 24 try { 25 std::regex re(pat); 26 } catch (const std::regex_error &ex) { 27 result = (ex.code() == std::regex_constants::error_escape); 28 } 29 return result; 30 } 31 32 int main() 33 { 34 assert(error_escape_thrown("[\\a]")); 35 assert(error_escape_thrown("\\a")); 36 assert(error_escape_thrown("\\")); 37 38 assert(error_escape_thrown("[\\e]")); 39 assert(error_escape_thrown("\\e")); 40 41 assert(error_escape_thrown("[\\c:]")); 42 assert(error_escape_thrown("\\c:")); 43 assert(error_escape_thrown("\\c")); 44 assert(!error_escape_thrown("[\\cA]")); 45 assert(!error_escape_thrown("\\cA")); 46 47 } 48