94627.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2020-2022 Free Software Foundation, Inc.
  2. //
  3. // This file is part of the GNU ISO C++ Library. This library is free
  4. // software; you can redistribute it and/or modify it under the
  5. // terms of the GNU General Public License as published by the
  6. // Free Software Foundation; either version 3, or (at your option)
  7. // any later version.
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License along
  13. // with this library; see the file COPYING3. If not see
  14. // <http://www.gnu.org/licenses/>.
  15. // { dg-do run { target c++11 } }
  16. // { dg-timeout-factor 2 }
  17. #include <regex>
  18. #include <testsuite_hooks.h>
  19. struct iterator
  20. {
  21. using value_type = char;
  22. using difference_type = std::ptrdiff_t;
  23. using reference = char&;
  24. using pointer = char*;
  25. using iterator_category = std::bidirectional_iterator_tag;
  26. iterator() : ptr() { }
  27. explicit iterator(pointer p) : ptr(p) { }
  28. iterator& operator++() { if (bang) throw 1; ++ptr; return *this; }
  29. iterator operator++(int) { auto copy = *this; ++*this; return copy; }
  30. iterator& operator--() { if (bang) throw 1; --ptr; return *this; }
  31. iterator operator--(int) { auto copy = *this; --*this; return copy; }
  32. reference operator*() const noexcept { return *ptr; }
  33. pointer operator->() const noexcept { return ptr; }
  34. bool operator==(iterator rhs) const noexcept { return ptr == rhs.ptr; }
  35. bool operator!=(iterator rhs) const noexcept { return ptr != rhs.ptr; }
  36. static bool bang;
  37. private:
  38. pointer ptr;
  39. };
  40. bool iterator::bang = false;
  41. int main()
  42. {
  43. char str[] = "abc";
  44. std::regex r(str);
  45. std::match_results<iterator> m;
  46. std::regex_match(iterator(str), iterator(str+3), m, r);
  47. iterator::bang = true;
  48. bool caught = false;
  49. try {
  50. (void) (m == m);
  51. } catch (int) {
  52. caught = true;
  53. }
  54. VERIFY( caught );
  55. caught = false;
  56. try {
  57. (void) (m != m);
  58. } catch (int) {
  59. caught = true;
  60. }
  61. VERIFY( caught );
  62. }