<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2137: Misleadingly constrained post-condition in the presence of exceptions</title>
<meta property="og:title" content="Issue 2137: Misleadingly constrained post-condition in the presence of exceptions">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2137.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#Open">Open</a> status.</em></p>
<h3 id="2137"><a href="lwg-active.html#2137">2137</a>. Misleadingly constrained post-condition in the presence of exceptions</h3>
<p><b>Section:</b> 28.6.7.3 <a href="https://wg21.link/re.regex.assign">[re.regex.assign]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2012-03-08 <b>Last modified:</b> 2024-10-03</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#re.regex.assign">issues</a> in [re.regex.assign].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The post-conditions of <code>basic_regex&lt;&gt;::assign</code> 28.6.7.3 <a href="https://wg21.link/re.regex.assign">[re.regex.assign]</a> p16 say:
</p>
<blockquote><p>
<span style="color:#C80000;font-weight:bold">If no exception is thrown,</span> <code>flags()</code> returns
<code>f</code> and <code>mark_count()</code> returns the number of marked sub-expressions within the expression.
</p></blockquote>
<p>
The default expectation in the library is that post-conditions only hold, if there is no failure
(see also <a href="lwg-active.html#2136" title="Postconditions vs. exceptions (Status: Open)">2136</a><sup><a href="https://cplusplus.github.io/LWG/issue2136" title="Latest snapshot">(i)</a></sup>), therefore the initial condition should be removed to prevent any
misunderstanding.
</p>

<p><i>[
2012-10 Portland: Move to Open
]</i></p>


<p>
A favorable resolution clearly depends on a favorable resolution to <a href="lwg-active.html#2136" title="Postconditions vs. exceptions (Status: Open)">2136</a><sup><a href="https://cplusplus.github.io/LWG/issue2136" title="Latest snapshot">(i)</a></sup>.
There is also a concern that this is just one example of where we would want to apply
such a wording clean-up, and which is really needed to resolve both this issue and
<a href="lwg-active.html#2136" title="Postconditions vs. exceptions (Status: Open)">2136</a><sup><a href="https://cplusplus.github.io/LWG/issue2136" title="Latest snapshot">(i)</a></sup> is a paper providing the clause 17 wording that gives the guarantee
for <i>postcondition</i> paragraphs, and then reviews clauses 18-30 to apply that
guarantee consistently.  We do not want to pick up these issues piecemeal, as we risk
opening many issues in an ongoing process.
</p>

<p><i>[2015-05-06 Lenexa: EricWF to write paper addressing 2136 and 2137]</i></p>


<p><i>[2024-10-03; Jonathan comments]</i></p>

<p>
I could find no other cases in the entire standard where we say something
like this in a <i>Postconditions</i>: element.
31.6.3.5.4 <a href="https://wg21.link/streambuf.virt.pback">[streambuf.virt.pback]</a> p2 says
"<i>Postconditions</i>: On return, the constraints of [...]"
which is probably redundant (postconditions are always "on return").
</p>


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

<blockquote><pre>
template &lt;class string_traits, class A&gt;
  basic_regex&amp; assign(const basic_string&lt;charT, string_traits, A&gt;&amp; s,
    flag_type f = regex_constants::ECMAScript);
</pre><blockquote>
<p>
[&hellip;]
<p/>
-15- <i>Effects</i>: Assigns the regular expression contained in the string <code>s</code>, interpreted according
the flags specified in <code>f</code>. If an exception is thrown, <code>*this</code> is unchanged.
<p/>
-16- <i>Postconditions</i>: <del>If no exception is thrown,</del> <code>flags()</code> returns <code>f</code> and
<code>mark_count()</code> returns the number of marked sub-expressions within the expression.
</p>
</blockquote>
</blockquote>






</body>
</html>
