Bug 94627 - [9/10 Regression] std::match_results equality comparisons should not be noexcept
Summary: [9/10 Regression] std::match_results equality comparisons should not be noexcept
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 10.0
: P2 normal
Target Milestone: 9.4
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-16 20:50 UTC by Jonathan Wakely
Modified: 2020-07-01 22:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 8.4.0
Known to fail: 10.0, 9.1.0
Last reconfirmed: 2020-04-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2020-04-16 20:50:17 UTC
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
Comment 1 GCC Commits 2020-07-01 20:46:29 UTC
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.
Comment 2 GCC Commits 2020-07-01 21:57:01 UTC
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)
Comment 3 GCC Commits 2020-07-01 22:21:23 UTC
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)
Comment 4 Jonathan Wakely 2020-07-01 22:21:38 UTC
Fixed for 9.4 and 10.2