<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2136: Postconditions vs. exceptions</title>
<meta property="og:title" content="Issue 2136: Postconditions vs. exceptions">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2136.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="2136"><a href="lwg-active.html#2136">2136</a>. Postconditions vs. exceptions</h3>
<p><b>Section:</b> 16.3.2 <a href="https://wg21.link/structure">[structure]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Jens Maurer <b>Opened:</b> 2012-03-08 <b>Last modified:</b> 2024-10-05</p>
<p><b>Priority: </b>3
</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 front matter in clause 17 should clarify that postconditions will not hold if a
standard library function exits via an exception. Postconditions or guarantees that
apply when an exception is thrown (beyond the basic guarantee) are described in an
"Exception safety" section.
</p>

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


<p>
Consensus that we do not clearly say this, and that we probably should.  A likely
location to describe the guarantees of <i>postconditions</i> could well be a new
sub-clause following 99 [res.on.required] which serves the same purpose
for <i>requires</i> clauses. However, we need such wording before we can make
progress.
</p>

<p>
Also, see <a href="lwg-active.html#2137" title="Misleadingly constrained post-condition in the presence of exceptions (Status: Open)">2137</a><sup><a href="https://cplusplus.github.io/LWG/issue2137" title="Latest snapshot">(i)</a></sup> for a suggestion that we want to see a paper resolving
both issues together.
</p>

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

<p>MC: Idea is to replace all such "If no exception" postconditions with "Exception safety" sections.</p>

<p><i>[2021-06-20; Daniel comments]</i></p>

<p>
An informal <a href="https://github.com/cplusplus/draft/issues/3612">editorial change suggestion</a> has
recently been made whose editorial implementation would promote the idea that the default assumption is
that <i>Postconditions:</i> are only met if the function doesn't exit with an exception.
<p/>
After analyzing all current existing <i>Postconditions:</i> elements the following seems to hold: Affected
by this issue are only non-<code>noexcept</code> functions and mostly non-constructor functions (unless the
<i>Postconditions:</i> element says something about the value of its arguments). Most existing
<i>Postconditions</i> seem to be intended to apply only in non-exceptional cases. I found some where
this is presumably not intended, namely those of the expressions <code>os &lt;&lt; x</code> and
<code>is &gt;&gt; v</code> in Tables [tab:rand.req.eng] and [tab:rand.req.dist], maybe also
30.11.2.4 <a href="https://wg21.link/time.zone.db.remote">[time.zone.db.remote]</a> p4.
<p/>
Nonetheless, the editorial change seems to be applicable even without having this issue resolved, because
it doesn't actually change the normative state by itself.
</p>

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



<p id="res-2136"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/N4988" title=" Working Draft, Programming Languages — C++">N4988</a>.</p>

<ol>
<li>
<p>Change 16.3.2.4 <a href="https://wg21.link/structure.specifications">[structure.specifications]</a> as indicated:</p>
<blockquote>
(3.6) &mdash;
<i>Postconditions</i>: the conditions (sometimes termed observable results)
established by the function <ins>when a call to it returns normally</ins>.
</blockquote>
</li>
</ol>





</body>
</html>
