This should exit cleanly: #include <regex> struct iterator { using value_type = char; using difference_type = std::ptrdiff_t; using reference = char&; using pointer = char*; using iterator_category = std::bidirectional_iterator_tag; iterator() : ptr() { } explicit iterator(pointer p) : ptr(p) { } iterator& operator++() { if (bang) throw 1; ++ptr; return *this; } iterator operator++(int) { auto copy = *this; ++*this; return copy; } iterator& operator--() { if (bang) throw 1; --ptr; return *this; } iterator operator--(int) { auto copy = *this; --*this; return copy; } reference operator*() const noexcept { return *ptr; } pointer operator->() const noexcept { return ptr; } bool operator==(iterator rhs) const noexcept { return ptr == rhs.ptr; } bool operator!=(iterator rhs) const noexcept { return ptr != rhs.ptr; } static bool bang; private: pointer ptr; }; bool iterator::bang = false; int main() { char str[] = "abc"; std::regex r(str); std::match_results<iterator> m; std::regex_match(iterator(str), iterator(str+3), m, r); iterator::bang = true; try { m == m; } catch (int) { } } Since g:c962b2c36f12 it terninates because I incorrectly added noexcept to the operator== and operator!= for std::match_results
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:a1a0dc4548979f8a340a7ea71624a52a20e1e0b3 commit r11-1770-ga1a0dc4548979f8a340a7ea71624a52a20e1e0b3 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Jul 1 21:01:15 2020 +0100 libstdc++: Remove noexcept from match_results comparisons (PR 94627) These functions can't be noexcept because the iterators stored in the sub_match objects can throw on any operation. libstdc++-v3/ChangeLog: PR libstdc++/94627 * include/bits/regex.h (operator==, operator!=): Remove noexcept equality comparisons for match_results. * testsuite/28_regex/match_results/94627.cc: New test.
The releases/gcc-10 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:4c994586cbd40a33f223aaaf90887afe97208543 commit r10-8409-g4c994586cbd40a33f223aaaf90887afe97208543 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Jul 1 21:01:15 2020 +0100 libstdc++: Remove noexcept from match_results comparisons (PR 94627) These functions can't be noexcept because the iterators stored in the sub_match objects can throw on any operation. libstdc++-v3/ChangeLog: PR libstdc++/94627 * include/bits/regex.h (operator==, operator!=): Remove noexcept equality comparisons for match_results. * testsuite/28_regex/match_results/94627.cc: New test. (cherry picked from commit a1a0dc4548979f8a340a7ea71624a52a20e1e0b3)
The releases/gcc-9 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:e4490e7771e4df28427cca5e113afe58a7fff8d5 commit r9-8713-ge4490e7771e4df28427cca5e113afe58a7fff8d5 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Jul 1 21:01:15 2020 +0100 libstdc++: Remove noexcept from match_results comparisons (PR 94627) These functions can't be noexcept because the iterators stored in the sub_match objects can throw on any operation. libstdc++-v3/ChangeLog: PR libstdc++/94627 * include/bits/regex.h (operator==, operator!=): Remove noexcept equality comparisons for match_results. * testsuite/28_regex/match_results/94627.cc: New test. (cherry picked from commit a1a0dc4548979f8a340a7ea71624a52a20e1e0b3)
Fixed for 9.4 and 10.2