<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 805: posix_error::posix_errno concerns</title>
<meta property="og:title" content="Issue 805: posix_error::posix_errno concerns">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue805.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="805"><a href="lwg-defects.html#805">805</a>. <code>posix_error::posix_errno</code> concerns</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> Jens Maurer <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>
<p>
19.5 <a href="https://wg21.link/syserr">[syserr]</a>
</p>

<blockquote><pre>
namespace posix_error {
  enum posix_errno {
    address_family_not_supported, // EAFNOSUPPORT
    ...
</pre></blockquote>

<p>
should rather use the new scoped-enum facility (9.8.1 <a href="https://wg21.link/dcl.enum">[dcl.enum]</a>),
which would avoid the necessity for a new <code>posix_error</code>
namespace, if I understand correctly.
</p>

<p><i>[
Further discussion:
]</i></p>


<blockquote>
<p>
See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf">N2347</a>,
Strongly Typed Enums, since renamed Scoped Enums.
</p>
<p>
Alberto Ganesh Barbati also raised this issue in private email, and also proposed the scoped-enum solution.
</p>
<p>
Nick Stoughton asked in Bellevue that <code>posix_error</code> and <code>posix_errno</code> not be used as names. The LWG agreed.
</p>
<p>
The wording for the Proposed resolution was provided by Beman Dawes.
</p>
</blockquote>


<p id="res-805"><b>Proposed resolution:</b></p>
<p>
Change System error support 19.5 <a href="https://wg21.link/syserr">[syserr]</a> as indicated:
</p>

<blockquote><pre>
<del>namespace posix_error {</del>
  enum <del>posix_errno</del> <ins>class errc</ins> {
    address_family_not_supported, // EAFNOSUPPORT
    ...
    wrong_protocol_type, // EPROTOTYPE
  };
<del>} // namespace posix_error</del>

template &lt;&gt; struct is_error_condition_enum&lt;<del>posix_error::posix_errno</del> <ins>errc</ins>&gt;
  : public true_type {}

<del>namespace posix_error {</del>
  error_code make_error_code(<del>posix_errno</del> <ins>errc</ins> e);
  error_condition make_error_condition(<del>posix_errno</del> <ins>errc</ins> e);
<del>} // namespace posix_error</del>
</pre></blockquote>

<p>
Change System error support 19.5 <a href="https://wg21.link/syserr">[syserr]</a> :
</p>

<blockquote><p>
<del>The <code>is_error_code_enum</code> and <code>is_error_condition_enum</code> templates may be
specialized for user-defined types to indicate that such a type is
eligible for class <code>error_code</code> and class <code>error_condition</code> automatic
conversions, respectively.</del>
</p></blockquote>

<p>
Change System error support 19.5 <a href="https://wg21.link/syserr">[syserr]</a> and its subsections:
</p>

<blockquote>
<ul>
<li>
remove all occurrences of <code>posix_error::</code>
</li>
<li>
change all instances of <code>posix_errno</code> to <code>errc</code>
</li>
<li>
change all instances of <code>posix_category</code> to <code>generic_category</code>
</li>
<li>
change all instances of <code>get_posix_category</code> to <code>get_generic_category</code>
</li>
</ul>
</blockquote>

<p>
Change Error category objects 19.5.3.5 <a href="https://wg21.link/syserr.errcat.objects">[syserr.errcat.objects]</a>, paragraph 2:
</p>

<blockquote><p>
<i>Remarks:</i> The object's <code>default_error_condition</code> and equivalent virtual
functions shall behave as specified for the class <code>error_category</code>. The
object's name virtual function shall return a pointer to the string
<del>"POSIX"</del> <ins>"generic"</ins>.
</p></blockquote>

<p>
Change 19.5.4.5 <a href="https://wg21.link/syserr.errcode.nonmembers">[syserr.errcode.nonmembers]</a> Class <code>error_code</code> non-member functions as indicated:
</p>

<blockquote>
<pre>
error_code make_error_code(<del>posix_errno</del> <ins>errc</ins> e);
</pre>

<blockquote><p>
<i>Returns:</i> <code>error_code(<ins>static_cast&lt;int&gt;(</ins>e<ins>)</ins>, <del>posix</del><ins>generic</ins>_category)</code>.
</p></blockquote>
</blockquote>

<p>
Change 19.5.5.5 <a href="https://wg21.link/syserr.errcondition.nonmembers">[syserr.errcondition.nonmembers]</a> Class <code>error_condition</code> non-member functions as indicated:
</p>

<blockquote>
<pre>
error_condition make_error_condition(<del>posix_errno</del> <ins>errc</ins> e);
</pre>

<blockquote><p>
<i>Returns:</i> <code>error_condition(<ins>static_cast&lt;int&gt;(</ins>e<ins>)</ins>, <del>posix</del><ins>generic</ins>_category)</code>.
</p></blockquote>
</blockquote>



<p><b>Rationale:</b></p>
<table border="1">
<tr>
<th colspan="2">Names Considered</th>
</tr>

<tr>
<td><code>portable</code></td>
<td>
Too non-specific. Did not wish to reserve such a common word in
namespace std. Not quite the right meaning, either.
</td>
</tr>

<tr>
<td><code>portable_error</code></td>
<td>
Too long. Explicit qualification is always required for scoped enums, so
a short name is desirable. Not quite the right meaning, either. May be
misleading because <code>*_error</code> in the std lib is usually an exception class
name.
</td>
</tr>

<tr>
<td><code>std_error</code></td>
<td>
Fairly short, yet explicit. But in fully qualified names like
<code>std::std_error::not_enough_memory</code>, the std_ would be unfortunate. Not
quite the right meaning, either. May be misleading because <code>*_error</code> in
the std lib is usually an exception class name.
</td>
</tr>

<tr>
<td><code>generic</code></td>
<td>
Short enough. The category could be <code>generic_category</code>. Fully qualified
names like <code>std::generic::not_enough_memory</code> read well. Reserving in
namespace std seems dicey.
</td>
</tr>

<tr>
<td><code>generic_error</code></td>
<td>
Longish. The category could be <code>generic_category</code>. Fully qualified names
like <code>std::generic_error::not_enough_memory</code> read well. Misleading because
<code>*_error</code> in the std lib is usually an exception class name.
</td>
</tr>

<tr>
<td><code>generic_err</code></td>
<td>
A bit less longish. The category could be <code>generic_category</code>. Fully
qualified names like <code>std::generic_err::not_enough_memory</code> read well.
</td>
</tr>

<tr>
<td><code>gen_err</code></td>
<td>
Shorter still. The category could be <code>generic_category</code>. Fully qualified
names like <code>std::gen_err::not_enough_memory</code> read well.
</td>
</tr>

<tr>
<td><code>generr</code></td>
<td>
Shorter still. The category could be <code>generic_category</code>. Fully qualified
names like <code>std::generr::not_enough_memory</code> read well.
</td>
</tr>

<tr>
<td><code>error</code></td>
<td>
Shorter still. The category could be <code>generic_category</code>. Fully qualified
names like <code>std::error::not_enough_memory</code> read well. Do we want to use
this general a name?
</td>
</tr>

<tr>
<td><code>err</code></td>
<td>
Shorter still. The category could be <code>generic_category</code>. Fully qualified
names like <code>std::err::not_enough_memory</code> read well. Although alone it
looks odd as a name, given the existing <code>errno</code> and <code>namespace std</code> names,
it seems fairly intuitive.
Problem: <code>err</code> is used throughout the standard library as an argument name
and in examples as a variable name; it seems too confusing to add yet
another use of the name.
</td>
</tr>

<tr>
<td><code>errc</code></td>
<td>
Short enough. The "c" stands for "constant". The category could be
<code>generic_category</code>. Fully qualified names like
<code>std::errc::not_enough_memory</code> read well. Although alone it looks odd as a
name, given the existing <code>errno</code> and <code>namespace std</code> names, it seems fairly
intuitive. There are no uses of <code>errc</code> in the current C++ standard.
</td>
</tr>
</table>





</body>
</html>
