| 1 |
// Copyright (C) 2020-2025 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 |
// { dg-timeout-factor 2 } |
| 20 |
|
| 21 |
#include <regex> |
| 22 |
#include <testsuite_hooks.h> |
| 23 |
|
| 24 |
struct iterator |
| 25 |
{ |
| 26 |
using value_type = char; |
| 27 |
using difference_type = std::ptrdiff_t; |
| 28 |
using reference = char&; |
| 29 |
using pointer = char*; |
| 30 |
using iterator_category = std::bidirectional_iterator_tag; |
| 31 |
|
| 32 |
iterator() : ptr() { } |
| 33 |
explicit iterator(pointer p) : ptr(p) { } |
| 34 |
|
| 35 |
iterator& operator++() { if (bang) throw 1; ++ptr; return *this; } |
| 36 |
iterator operator++(int) { auto copy = *this; ++*this; return copy; } |
| 37 |
iterator& operator--() { if (bang) throw 1; --ptr; return *this; } |
| 38 |
iterator operator--(int) { auto copy = *this; --*this; return copy; } |
| 39 |
|
| 40 |
reference operator*() const noexcept { return *ptr; } |
| 41 |
pointer operator->() const noexcept { return ptr; } |
| 42 |
|
| 43 |
bool operator==(iterator rhs) const noexcept { return ptr == rhs.ptr; } |
| 44 |
bool operator!=(iterator rhs) const noexcept { return ptr != rhs.ptr; } |
| 45 |
|
| 46 |
static bool bang; |
| 47 |
|
| 48 |
private: |
| 49 |
pointer ptr; |
| 50 |
}; |
| 51 |
|
| 52 |
bool iterator::bang = false; |
| 53 |
|
| 54 |
int main() |
| 55 |
{ |
| 56 |
char str[] = "abc"; |
| 57 |
std::regex r(str); |
| 58 |
std::match_results<iterator> m; |
| 59 |
std::regex_match(iterator(str), iterator(str+3), m, r); |
| 60 |
iterator::bang = true; |
| 61 |
bool caught = false; |
| 62 |
try { |
| 63 |
(void) (m == m); |
| 64 |
} catch (int) { |
| 65 |
caught = true; |
| 66 |
} |
| 67 |
VERIFY( caught ); |
| 68 |
caught = false; |
| 69 |
|
| 70 |
try { |
| 71 |
(void) (m != m); |
| 72 |
} catch (int) { |
| 73 |
caught = true; |
| 74 |
} |
| 75 |
VERIFY( caught ); |
| 76 |
} |