This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.

2205. Problematic postconditions of regex_match and regex_search

Section: 32.10.2 [re.alg.match], 32.10.3 [re.alg.search] Status: C++14 Submitter: Pete Becker Opened: 2012-10-24 Last modified: 2017-07-05

Priority: 0

View all other issues in [re.alg.match].

View all issues with C++14 status.

Discussion:

Table 142 lists post-conditions on the match_results object when a call to regex_match succeeds. regex_match is required to match the entire target sequence. The post-condition for m[0].matched is "true if a full match was found." Since these are conditions for a successful search which is, by definition, a full match, the post-condition should be simply "true".

There's an analogous probem in Table 143: the condition for m[0].matched is "true if a match was found, false otherwise." But Table 143 gives post-conditions for a successful match, so the condition should be simply "true".

Furthermore, they have explicit requirements for m[0].first, m[0].second, and m[0].matched. They also have requirements for the other elements of m, described as m[n].first, m[n].second, and m[n].matched, in each case qualifying the value of n as "for n < m.size()". Since there is an explicit description for n == 0, this qualification should be "for 0 < n < m.size()" in all 6 places.

[Issaquah 2014-02-11: Move to Immediate]

Proposed resolution:

This wording is relative to N3376.

  1. Change Table 142 as indicated:

    Table 142 — Effects of regex_match algorithm
    Element Value
    m[0].first first
    m[0].second last
    m[0].matched true if a full match was found.
    m[n].first For all integers 0 < n < m.size(), the start of the sequence that matched sub-expression n.
    Alternatively, if subexpression n did not participate in the match, then last.
    m[n].second For all integers 0 < n < m.size(), the end of the sequence that matched sub-expression n.
    Alternatively, if sub-expression n did not participate in the match, then last.
    m[n].matched For all integers 0 < n < m.size(), true if sub-expression n participated in the match, false otherwise.
  2. Change Table 143 as indicated:

    Table 143 — Effects of regex_search algorithm
    Element Value
    m[0].first The start of the sequence of characters that matched the regular expression
    m[0].second The end of the sequence of characters that matched the regular expression
    m[0].matched true if a match was found, and false otherwise.
    m[n].first For all integers 0 < n < m.size(), the start of the sequence that matched sub-expression n.
    Alternatively, if subexpression n did not participate in the match, then last.
    m[n].second For all integers 0 < n < m.size(), the end of the sequence that matched sub-expression n.
    Alternatively, if sub-expression n did not participate in the match, then last.
    m[n].matched For all integers 0 < n < m.size(), true if sub-expression n participated in the match, false otherwise.