bad_repeat.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: libcpp-no-exceptions
  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. #include "test_macros.h"
  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(int, char**)
  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. return 0;
  37. }