excessive_brace_count.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // <regex>
  9. // UNSUPPORTED: libcpp-no-exceptions
  10. // UNSUPPORTED: c++98, c++03
  11. // the "n" in `a{n}` should be within the numeric limits.
  12. #include <regex>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. int main(int, char**) {
  16. for (std::regex_constants::syntax_option_type op :
  17. {std::regex::basic, std::regex::grep}) {
  18. try {
  19. TEST_IGNORE_NODISCARD std::regex("a\\{100000000000000000\\}", op);
  20. assert(false);
  21. } catch (const std::regex_error &e) {
  22. assert(e.code() == std::regex_constants::error_badbrace);
  23. }
  24. }
  25. for (std::regex_constants::syntax_option_type op :
  26. {std::regex::ECMAScript, std::regex::extended, std::regex::egrep,
  27. std::regex::awk}) {
  28. try {
  29. TEST_IGNORE_NODISCARD std::regex("a{100000000000000000}", op);
  30. assert(false);
  31. } catch (const std::regex_error &e) {
  32. assert(e.code() == std::regex_constants::error_badbrace);
  33. }
  34. }
  35. return 0;
  36. }