1 // Copyright (C) 2020 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 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17 
18 // { dg-do run { target c++11 } }
19 
20 #include <regex>
21 #include <testsuite_hooks.h>
22 
23 struct iterator
24 {
25   using value_type = char;
26   using difference_type = std::ptrdiff_t;
27   using reference = char&;
28   using pointer = char*;
29   using iterator_category = std::bidirectional_iterator_tag;
30 
iteratoriterator31   iterator() : ptr() { }
iteratoriterator32   explicit iterator(pointer p) : ptr(p) { }
33 
operator ++iterator34   iterator& operator++() { if (bang) throw 1; ++ptr; return *this; }
operator ++iterator35   iterator operator++(int) { auto copy = *this; ++*this; return copy; }
operator --iterator36   iterator& operator--() { if (bang) throw 1; --ptr; return *this; }
operator --iterator37   iterator operator--(int) { auto copy = *this; --*this; return copy; }
38 
operator *iterator39   reference operator*() const noexcept { return *ptr; }
operator ->iterator40   pointer operator->() const noexcept { return ptr; }
41 
operator ==iterator42   bool operator==(iterator rhs) const noexcept { return ptr == rhs.ptr; }
operator !=iterator43   bool operator!=(iterator rhs) const noexcept { return ptr != rhs.ptr; }
44 
45   static bool bang;
46 
47 private:
48   pointer ptr;
49 };
50 
51 bool iterator::bang = false;
52 
main()53 int main()
54 {
55   char str[] = "abc";
56   std::regex r(str);
57   std::match_results<iterator> m;
58   std::regex_match(iterator(str), iterator(str+3), m, r);
59   iterator::bang = true;
60   bool caught = false;
61   try {
62     (void) (m == m);
63   } catch (int) {
64     caught = true;
65   }
66   VERIFY( caught );
67   caught = false;
68 
69   try {
70     (void) (m != m);
71   } catch (int) {
72     caught = true;
73   }
74   VERIFY( caught );
75 }
76