<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2205: Problematic postconditions of regex_match and regex_search</title>
<meta property="og:title" content="Issue 2205: Problematic postconditions of regex_match and regex_search">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2205.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++14">C++14</a> status.</em></p>
<h3 id="2205"><a href="lwg-defects.html#2205">2205</a>. Problematic postconditions of <code>regex_match</code> and <code>regex_search</code></h3>
<p><b>Section:</b> 28.6.10.2 <a href="https://wg21.link/re.alg.match">[re.alg.match]</a>, 28.6.10.3 <a href="https://wg21.link/re.alg.search">[re.alg.search]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Pete Becker <b>Opened:</b> 2012-10-24 <b>Last modified:</b> 2017-07-05</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#re.alg.match">issues</a> in [re.alg.match].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
Table 142 lists post-conditions on the <code>match_results</code> object when a call to <code>regex_match</code> succeeds. 
<code>regex_match</code> is required to match the entire target sequence. The post-condition for <code>m[0].matched</code> 
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".
</p>
<p>
There's an analogous probem in Table 143: the condition for <code>m[0].matched</code> 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".
</p>
<p>
Furthermore, they have explicit requirements for <code>m[0].first</code>, <code>m[0].second</code>, and <code>m[0].matched</code>. 
They also have requirements for the other elements of <code>m</code>, described as <code>m[n].first</code>, <code>m[n].second</code>, 
and <code>m[n].matched</code>, in each case qualifying the value of <code>n</code> as "for <code>n &lt; m.size()</code>". Since 
there is an explicit description for <code>n == 0</code>, this qualification should be "for <code>0 &lt; n &lt; m.size()</code>" 
in all 6 places.
</p>

<p><i>[Issaquah 2014-02-11: Move to Immediate]</i></p>




<p id="res-2205"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3376.</p>

<ol>
<li><p>Change Table 142 as indicated:</p>

<table border="1">
<caption>Table 142 &mdash; Effects of <code>regex_match</code> algorithm</caption>
<tr>
<th>Element</th>
<th>Value</th>
</tr> 

<tr>
<td colspan="2" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>m[0].first</code>
</td>
<td>
<code>first</code>
</td>
</tr>

<tr>
<td>
<code>m[0].second</code>
</td>
<td>
<code>last</code>
</td>
</tr>

<tr>
<td>
<code>m[0].matched</code>
</td>
<td>
<code>true</code> <del>if a full match was found.</del>
</td>
</tr>

<tr>
<td>
<code>m[n].first</code>
</td>
<td>
For all integers <code><ins>0 &lt;</ins> n &lt; m.size()</code>, the start of the sequence
that matched sub-expression <code>n</code>.<br/> 
Alternatively, if subexpression <code>n</code> did not participate in the match, then <code>last</code>.
</td>
</tr>

<tr>
<td>
<code>m[n].second</code>
</td>
<td>
For all integers <code><ins>0 &lt;</ins> n &lt; m.size()</code>, the end of the sequence that
matched sub-expression <code>n</code>.<br/> 
Alternatively, if sub-expression <code>n</code> did not participate in the match, then <code>last</code>.
</td>
</tr>

<tr>
<td>
<code>m[n].matched</code>
</td>
<td>
For all integers <code><ins>0 &lt;</ins> n &lt; m.size()</code>, <code>true</code> if sub-expression 
<code>n</code> participated in the match, <code>false</code> otherwise.
</td>
</tr>

</table>
</li>

<li><p>Change Table 143 as indicated:</p>

<table border="1">
<caption>Table 143 &mdash; Effects of <code>regex_search</code> algorithm</caption>
<tr>
<th>Element</th>
<th>Value</th>
</tr> 

<tr>
<td colspan="2" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>m[0].first</code>
</td>
<td>
The start of the sequence of characters that matched the regular expression
</td>
</tr>

<tr>
<td>
<code>m[0].second</code>
</td>
<td>
The end of the sequence of characters that matched the regular expression
</td>
</tr>

<tr>
<td>
<code>m[0].matched</code>
</td>
<td>
<code>true</code> <del>if a match was found, and false otherwise.</del>
</td>
</tr>

<tr>
<td>
<code>m[n].first</code>
</td>
<td>
For all integers <code><ins>0 &lt;</ins> n &lt; m.size()</code>, the start of the sequence
that matched sub-expression <code>n</code>.<br/> 
Alternatively, if subexpression <code>n</code> did not participate in the match, then <code>last</code>.
</td>
</tr>

<tr>
<td>
<code>m[n].second</code>
</td>
<td>
For all integers <code><ins>0 &lt;</ins> n &lt; m.size()</code>, the end of the sequence that
matched sub-expression <code>n</code>.<br/> 
Alternatively, if sub-expression <code>n</code> did not participate in the match, then <code>last</code>.
</td>
</tr>

<tr>
<td>
<code>m[n].matched</code>
</td>
<td>
For all integers <code><ins>0 &lt;</ins> n &lt; m.size()</code>, <code>true</code> if sub-expression 
<code>n</code> participated in the match, <code>false</code> otherwise.
</td>
</tr>

</table>
</li>

</ol>





</body>
</html>
