<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 804: Some problems with classes error_code/error_condition</title>
<meta property="og:title" content="Issue 804: Some problems with classes error_code/error_condition">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue804.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#CD1">CD1</a> status.</em></p>
<h3 id="804"><a href="lwg-defects.html#804">804</a>. Some problems with classes <code>error_code</code>/<code>error_condition</code></h3>
<p><b>Section:</b> 19.5 <a href="https://wg21.link/syserr">[syserr]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2008-02-24 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#syserr">issues</a> in [syserr].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<ol style="list-style-type:upper-alpha">
<li>
<p>
19.5.4.1 <a href="https://wg21.link/syserr.errcode.overview">[syserr.errcode.overview]</a>/1, class <code>error_code</code> and
19.5.5.1 <a href="https://wg21.link/syserr.errcondition.overview">[syserr.errcondition.overview]</a>/, class <code>error_condition</code> synopses
declare an expository data member <code>cat_</code>:
</p>
<blockquote><pre>
const error_category&amp; cat_; // exposition only
</pre></blockquote>
<p>
which is used to define the semantics of several members. The decision
to use a member of reference type lead to several problems:
</p>
<ol>
<li>
The classes are not <code>(Copy)Assignable</code>, which is probably not the intent.
</li>
<li>
The post conditions of all modifiers from
19.5.4.3 <a href="https://wg21.link/syserr.errcode.modifiers">[syserr.errcode.modifiers]</a> and 19.5.5.3 <a href="https://wg21.link/syserr.errcondition.modifiers">[syserr.errcondition.modifiers]</a>, resp.,
cannot be fulfilled.
</li>
</ol>
<p>
The simple fix would be to replace the reference by a pointer member.
</p>
</li>

<li>
I would like to give the editorial remark that in both classes the
constrained <code>operator=</code>
overload (template with <code>ErrorCodeEnum</code> argument) makes in invalid
usage of <code>std::enable_if</code>: By using the default value for the second <code>enable_if</code>
parameter the return type would be defined to be <code>void&amp;</code> even in otherwise
valid circumstances - this return type must be explicitly provided (In
<code>error_condition</code> the first declaration uses an explicit value, but of wrong
type).
</li>

<li>
The member function <code>message</code> throws clauses (
19.5.3.2 <a href="https://wg21.link/syserr.errcat.virtuals">[syserr.errcat.virtuals]</a>/10, 19.5.4.4 <a href="https://wg21.link/syserr.errcode.observers">[syserr.errcode.observers]</a>/8, and
19.5.5.4 <a href="https://wg21.link/syserr.errcondition.observers">[syserr.errcondition.observers]</a>/6) guarantee "throws nothing",
although
they return a <code>std::string</code> by value, which might throw in out-of-memory
conditions (see related issue <a href="lwg-defects.html#771" title="Impossible throws clause in [string.conversions] (Status: CD1)">771</a><sup><a href="https://cplusplus.github.io/LWG/issue771" title="Latest snapshot">(i)</a></sup>).
</li>
</ol>

<p><i>[
Sophia Antipolis:
]</i></p>


<blockquote>
<p>
Part A: NAD (editorial), cleared by the resolution of issue <a href="lwg-closed.html#832" title="Applying constexpr to System error support (Status: NAD)">832</a><sup><a href="https://cplusplus.github.io/LWG/issue832" title="Latest snapshot">(i)</a></sup>.
</p>
<p>
Part B: Technically correct, save for typo. Rendered moot by the concept proposal 
(<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2620.html">N2620</a>) NAD (editorial).
</p>
<p>
Part C: We agree; this is consistent with the resolution of issue <a href="lwg-closed.html#721" title="wstring_convert inconsistensies (Status: NAD)">721</a><sup><a href="https://cplusplus.github.io/LWG/issue721" title="Latest snapshot">(i)</a></sup>.
</p>
<p>
Howard: please ping Beman, asking him to clear away parts A and B from
the wording in the proposed resolution, so it is clear to the editor
what needs to be applied to the working paper.
</p>
<p>
Beman provided updated wording. Since issue <a href="lwg-closed.html#832" title="Applying constexpr to System error support (Status: NAD)">832</a><sup><a href="https://cplusplus.github.io/LWG/issue832" title="Latest snapshot">(i)</a></sup> is not going
forward, the provided wording includes resolution of part A.
</p>
</blockquote>



<p id="res-804"><b>Proposed resolution:</b></p>

<p>
Resolution of part A:
</p>
<blockquote>
<p>
Change 19.5.4.1 <a href="https://wg21.link/syserr.errcode.overview">[syserr.errcode.overview]</a> Class error_code overview synopsis as indicated:
</p>

<blockquote><pre>
private:
  int val_;                    // exposition only
  const error_category<del>&amp;</del><ins>*</ins> cat_; // exposition only
</pre></blockquote>

<p>
Change 19.5.4.2 <a href="https://wg21.link/syserr.errcode.constructors">[syserr.errcode.constructors]</a> Class error_code constructors as indicated:
</p>

<blockquote>
<pre>
error_code();
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>error_code</code>.
</p>
<p>
<i>Postconditions:</i> <code>val_ == 0</code> and <code>cat_ == <ins>&amp;</ins>system_category</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
<pre>
error_code(int val, const error_category&amp; cat);
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>error_code</code>.
</p>
<p>
<i>Postconditions:</i> <code>val_ == val</code> and <code>cat_ == <ins>&amp;</ins>cat</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>

<p>
Change 19.5.4.3 <a href="https://wg21.link/syserr.errcode.modifiers">[syserr.errcode.modifiers]</a> Class error_code modifiers as indicated:
</p>

<blockquote>
<pre>
void assign(int val, const error_category&amp; cat);
</pre>
<blockquote>
<p>
<i>Postconditions:</i> <code>val_ == val</code> and <code>cat_ == <ins>&amp;</ins>cat</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>

<p>
Change 19.5.4.4 <a href="https://wg21.link/syserr.errcode.observers">[syserr.errcode.observers]</a> Class error_code observers as indicated:
</p>

<blockquote><pre>
const error_category&amp; category() const;
</pre><blockquote>
<p>
<i>Returns:</i> <code><ins>*</ins>cat_</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>

<p>
Change 19.5.5.1 <a href="https://wg21.link/syserr.errcondition.overview">[syserr.errcondition.overview]</a> Class error_condition overview synopsis as indicated:
</p>

<blockquote><pre>
private:
  int val_;                    // exposition only
  const error_category<del>&amp;</del><ins>*</ins> cat_; // exposition only
</pre></blockquote>

<p>
Change 19.5.5.2 <a href="https://wg21.link/syserr.errcondition.constructors">[syserr.errcondition.constructors]</a> Class error_condition constructors as indicated:
</p>
<p><i>[
(If the proposed resolution of issue <a href="lwg-defects.html#805" title="posix_error::posix_errno concerns (Status: CD1)">805</a><sup><a href="https://cplusplus.github.io/LWG/issue805" title="Latest snapshot">(i)</a></sup> has already been applied, the
name <code>posix_category</code> will have been changed to <code>generic_category</code>. That has
no effect on this resolution.)
]</i></p>


<blockquote>
<pre>
error_condition();
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>error_condition</code>.
</p>
<p>
<i>Postconditions:</i> <code>val_ == 0</code> and <code>cat_ == <ins>&amp;</ins>posix_category</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
<pre>
error_condition(int val, const error_category&amp; cat);
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>error_condition</code>.
</p>
<p>
<i>Postconditions:</i> <code>val_ == val</code> and <code>cat_ == <ins>&amp;</ins>cat</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>

<p>
Change 19.5.5.3 <a href="https://wg21.link/syserr.errcondition.modifiers">[syserr.errcondition.modifiers]</a> Class error_condition modifiers as indicated:
</p>

<blockquote><pre>
void assign(int val, const error_category&amp; cat);
</pre><blockquote>
<p>
<i>Postconditions:</i> <code>val_ == val</code> and <code>cat_ == <ins>&amp;</ins>cat</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>

<p>
Change 19.5.5.4 <a href="https://wg21.link/syserr.errcondition.observers">[syserr.errcondition.observers]</a> Class error_condition observers as indicated:
</p>

<blockquote><pre>
const error_category&amp; category() const;
</pre><blockquote>
<p>
<i>Returns:</i> <code><ins>*</ins>cat_</code>.
</p>
<p>
<i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>
</blockquote>

<p>
Resolution of part C:
</p>

<blockquote>

<p>
In 19.5.3.2 <a href="https://wg21.link/syserr.errcat.virtuals">[syserr.errcat.virtuals]</a>, remove the throws clause p. 10.
</p>

<blockquote>
<pre>
virtual string message(int ev) const = 0;
</pre>

<blockquote>
<p>
<i>Returns:</i> A string that describes the error condition denoted by <code>ev</code>.
</p>
<p>
<del><i>Throws:</i> Nothing.</del>
</p>
</blockquote>
</blockquote>

<p>
In 19.5.4.4 <a href="https://wg21.link/syserr.errcode.observers">[syserr.errcode.observers]</a>, remove the throws clause p. 8.
</p>

<blockquote>
<pre>
string message() const;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>category().message(value())</code>.
</p>
<p>
<del><i>Throws:</i> Nothing.</del>
</p>
</blockquote>
</blockquote>

<p>
In 19.5.5.4 <a href="https://wg21.link/syserr.errcondition.observers">[syserr.errcondition.observers]</a>, remove the throws clause p. 6.
</p>

<blockquote>
<pre>
string message() const;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>category().message(value())</code>.
</p>
<p>
<del><i>Throws:</i> Nothing.</del>
</p>
</blockquote>
</blockquote>

</blockquote>






</body>
</html>
