bad_escape.pass.cpp 1.2 KB

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