bad_repeat.pass.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_badrepeat_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_badrepeat);
  23. }
  24. return result;
  25. }
  26. int main()
  27. {
  28. assert(error_badrepeat_thrown("?a"));
  29. assert(error_badrepeat_thrown("*a"));
  30. assert(error_badrepeat_thrown("+a"));
  31. assert(error_badrepeat_thrown("{a"));
  32. assert(error_badrepeat_thrown("?(a+)"));
  33. assert(error_badrepeat_thrown("*(a+)"));
  34. assert(error_badrepeat_thrown("+(a+)"));
  35. assert(error_badrepeat_thrown("{(a+)"));
  36. }