https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64781

            Bug ID: 64781
           Summary: regex out-of-range submatches should represent an
                    unmatched sub-expression
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaballo86 at hotmail dot com

The following snippet fails with a runtime assertion:

    #include <regex>
    #include <cassert>

    int main() {
      std::match_results<const char*> m;
      const char s[] = "a";
      assert(std::regex_search(s, m, std::regex("a")));

      assert(m.size() == 1);

      assert(m[0].first == s+0);
      assert(m[0].second == s+1);
      assert(m[0].matched == true);

      assert(m[42].first == s+1); // fires
      assert(m[42].second == s+1); // fires
      assert(m[42].matched == false);
    }

28.10.4 [re.results.acc]/8 says "If `n >= size()` then returns a `sub_match`
object representing an unmatched sub-expression."

While the term "unmatched sub-expression" does not appear anywhere else in the
standard, this is presumably 28.10 [re.results]/4 "If the sub-expression `n`
participated in a regular expression match then the `sub_match` member
`matched` evaluates to `true`, and members `first` and `second` denote the
range of characters `[first,second)` which formed that match. Otherwise
`matched` is `false`, and members `first` and `second` point to the end of the
sequence that was searched."

According to that, `m[n].first == m[n].last == s+1` should hold for `n >= 1`.

Reply via email to