84110.cc 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // { dg-do run { target c++11 } }
  2. // { dg-timeout-factor 2 }
  3. #include <regex>
  4. #include <string>
  5. #include <testsuite_hooks.h>
  6. void test01()
  7. {
  8. const std::string s(1ul, '\0');
  9. std::regex re(s);
  10. VERIFY( std::regex_match(s, re) ); // PR libstdc++/84110
  11. #if __cpp_exceptions
  12. using namespace std::regex_constants;
  13. // See https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582486.html
  14. using std::regex_constants::extended;
  15. for (auto syn : {basic, extended, awk, grep, egrep})
  16. {
  17. try
  18. {
  19. std::regex{s, syn}; // '\0' is not valid for other grammars
  20. VERIFY( false );
  21. }
  22. catch (const std::regex_error&)
  23. {
  24. }
  25. }
  26. #endif
  27. }
  28. void test02()
  29. {
  30. const std::string s("uh-\0h", 5);
  31. std::regex re(s);
  32. VERIFY( std::regex_match(s, re) );
  33. }
  34. int main()
  35. {
  36. test01();
  37. test02();
  38. }