bad_escape.pass.cpp 1.2 KB

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