<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3629: make_error_code and make_error_condition are customization points</title>
<meta property="og:title" content="Issue 3629: make_error_code and make_error_condition are customization points">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3629.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++23">C++23</a> status.</em></p>
<h3 id="3629"><a href="lwg-defects.html#3629">3629</a>. <code>make_error_code</code> and <code>make_error_condition</code> are customization points</h3>
<p><b>Section:</b> 19.5 <a href="https://wg21.link/syserr">[syserr]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2021-10-31 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</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#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The rule in 16.4.2.2 <a href="https://wg21.link/contents">[contents]</a> means that the calls to
<code>make_error_code</code> in 19.5.4.2 <a href="https://wg21.link/syserr.errcode.constructors">[syserr.errcode.constructors]</a>
and 19.5.4.3 <a href="https://wg21.link/syserr.errcode.modifiers">[syserr.errcode.modifiers]</a> are required to call
<code>std::make_error_code</code>,
which means program-defined error codes do not work.
The same applies to the <code>make_error_condition</code> calls in
19.5.5.2 <a href="https://wg21.link/syserr.errcondition.constructors">[syserr.errcondition.constructors]</a> and
19.5.5.3 <a href="https://wg21.link/syserr.errcondition.modifiers">[syserr.errcondition.modifiers]</a>.
</p>

<p>
They need to use ADL.
This is what all known implementations (including Boost.System) do.
</p>

<p><i>[2022-01-29; Reflector poll]</i></p>

<p>
Set priority to 2 after reflector poll.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4901">N4901</a>.
</p>

<ol>
<li><p>Modify 19.5.2 <a href="https://wg21.link/system.error.syn">[system.error.syn]</a> as indicated:</p>

<blockquote>
<p>
-1-
The value of each <code>enum errc</code> constant shall be the same as the
value of the <code>&lt;cerrno&gt;</code> macro shown in the above synopsis.
Whether or not the <code>&lt;system_error&gt;</code> implementation exposes
the <code>&lt;cerrno&gt;</code> macros is unspecified.
</p>

<p>
<ins>
-?-
Invocations of <code>make_error_code</code> and
<code>make_error_condition</code> shown in subclause 19.5 <a href="https://wg21.link/syserr">[syserr]</a>
select a function to call via overload resolution (12.2 <a href="https://wg21.link/over.match">[over.match]</a>)
on a candidate set that includes the lookup set found by
argument dependent lookup (6.5.4 <a href="https://wg21.link/basic.lookup.argdep">[basic.lookup.argdep]</a>).
</ins>
</p>

<p>
-2-
The <code>is_error_code_enum</code> and <code>is_error_condition_enum</code>
templates may be specialized for program-defined types to indicate that such
types are eligible for <code>class error_code</code> and
<code>class error_condition</code> implicit conversions, respectively.
</p>

<p>
<ins>
<em>[Note 1:</em>
Conversions from such types are done by program-defined overloads of
<code>make_error_code</code> and <code>make_error_condition</code>,
found by ADL. <em>&mdash;end note]</em>
</ins>
</p>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2022-08-25; Jonathan Wakely provides improved wording]</i></p>

<p>
Discussed in LWG telecon and decided on new direction:
<ul>
<li>Add <code>make_error_code</code> and <code>make_error_condition</code>
to 16.4.2.2 <a href="https://wg21.link/contents">[contents]</a> as done for <code>swap</code>.
Describe form of lookup used for them.</li>
<li>Respecify <code>error_code</code> and <code>error_condition</code>
constructors in terms of "<i>Effects</i>: Equivalent to" so that the
requirements on program-defined overloads found by ADL are implied by those
effects.</li>
</ul>
</p>

<p><i>[2022-09-07; Jonathan Wakely revises wording]</i></p>


<p>
Discussed in LWG telecon. Decided to change "established as-if by performing
unqualified name lookup and argument-dependent lookup"
to simply "established as-if by performing argument-dependent lookup".
</p>
<p>
This resolves the question of whether <code>std::make_error_code(errc)</code>,
<code>std::make_error_code(io_errc)</code>, etc. should be visible to the
unqualified name lookup. This affects whether a program-defined type that
specializes <code>is_error_code_enum</code> but doesn't provide an overload of
<code>make_error_code</code> should find the overloads in namespace <code>std</code>
and consider them for overload resolution, via implicit conversion to
<code>std::errc</code>, <code>std::io_errc</code>, etc.
</p>

<p><i>[2022-09-23; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after seven votes in favour during reflector poll.
</p>

<p><i>[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3629"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4910" title=" Working Draft, Standard for Programming Language C++">N4910</a>.
</p>

<ul>
<li><p>Modify 16.4.2.2 <a href="https://wg21.link/contents">[contents]</a> as indicated:</p>

<blockquote>
<p>-3-
Whenever an unqualified name other than <code>swap</code><ins>,
<code>make_error_code</code>, or <code>make_error_condition</code></ins>
is used in the specification of a declaration <code>D</code> in
17 <a href="https://wg21.link/support">[support]</a> through 32 <a href="https://wg21.link/thread">[thread]</a> or D <a href="https://wg21.link/depr">[depr]</a>,
its meaning is established as-if by performing unqualified name lookup
(6.5.3 <a href="https://wg21.link/basic.lookup.unqual">[basic.lookup.unqual]</a>) in the context of <code>D</code>.
</p>

<p>
[<i>Note 1</i>:
Argument-dependent lookup is not performed.
&mdash; <i>end note</i>]
</p>

<p>
Similarly, the meaning of a <i>qualified-id</i> is established as-if by
performing qualified name lookup (6.5.5 <a href="https://wg21.link/basic.lookup.qual">[basic.lookup.qual]</a>)
in the context of <code>D</code>.
</p>

<p>
[<i>Example 1</i>:
The reference to <code>is_array_v</code> in the specification of
<code>std::to_array</code> (23.3.3.6 <a href="https://wg21.link/array.creation">[array.creation]</a>)
refers to <code>::std::is_array_v</code>.
&mdash; <i>end example</i>]
</p>

<p>
[<i>Note 2</i>:
Operators in expressions (12.2.2.3 <a href="https://wg21.link/over.match.oper">[over.match.oper]</a>)
are not so constrained; see 16.4.6.4 <a href="https://wg21.link/global.functions">[global.functions]</a>.
&mdash; <i>end note</i>]
</p>

<p>
The meaning of the unqualified name <code>swap</code> is established
in an overload resolution context for swappable values
(16.4.4.3 <a href="https://wg21.link/swappable.requirements">[swappable.requirements]</a>).
<ins>
The meanings of the unqualified names
<code>make_error_code</code> and <code>make_error_condition</code>
are established as-if by performing
argument-dependent lookup (6.5.4 <a href="https://wg21.link/basic.lookup.argdep">[basic.lookup.argdep]</a>).
</ins>
</p>

</blockquote>
</li>

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

<blockquote>
<pre>error_code() noexcept;</pre>
<p>
<del>
-1- <i>Postconditions</i>:
<code>val_ == 0</code> and <code>cat_ == &amp;system_category()</code>.
</del>
<br/>
<ins>
-1- <i>Effects</i>:
Initializes <code>val_</code> with <code>0</code>
and <code>cat_</code> with <code>&amp;system_category()</code>.
</ins>
</p>

<pre>error_code(int val, const error_category&amp; cat) noexcept;</pre>
<p>
<del>
-2- <i>Postconditions</i>:
<code>val_ == val</code> and <code>cat_ == &amp;cat</code>.
</del>
<br/>
<ins>
-2- <i>Effects</i>:
Initializes <code>val_</code> with <code>val</code>
and <code>cat_</code> with <code>&amp;cat</code>.
</ins>
</p>

<pre>template&lt;class ErrorCodeEnum&gt;
  error_code(ErrorCodeEnum e) noexcept;</pre>
<p>-3- <i>Constraints</i>:
<code>is_error_code_enum_v&lt;ErrorCodeEnum&gt;</code> is <code>true</code>.
</p>
<p>
<del>
-4- <i>Postconditions</i>:
<code>*this == make_error_code(e)</code>.
</del>
<br/>
<ins>
-4- <i>Effects</i>: Equivalent to:
</ins>
<blockquote><pre><ins>error_code ec = make_error_code(e);
assign(ec.value(), ec.category());
</ins></pre></blockquote>
</p>
</blockquote>
</li>

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

<blockquote>
<pre>template&lt;class ErrorCodeEnum&gt;
  error_code&amp; operator=(ErrorCodeEnum e) noexcept;</pre>
<p>-2- <i>Constraints</i>:
<code>is_error_code_enum_v&lt;ErrorCodeEnum&gt;</code> is <code>true</code>.
</p>
<p>
<del>
-3- <i>Postconditions</i>:
<code>*this == make_error_code(e)</code>.
</del>
<br/>
<ins>
-3- <i>Effects</i>: Equivalent to:
</ins>
<blockquote><pre><ins>error_code ec = make_error_code(e);
assign(ec.value(), ec.category());
</ins></pre></blockquote>
</p>
<p>
-4- <i>Returns</i>: <code>*this</code>.
</p>
</blockquote>

</li>

<li><p>Modify 19.5.5.2 <a href="https://wg21.link/syserr.errcondition.constructors">[syserr.errcondition.constructors]</a> as indicated:</p>

<blockquote>
<pre>error_condition() noexcept;</pre>
<p>
<del>
-1- <i>Postconditions</i>:
<code>val_ == 0</code> and <code>cat_ == &amp;generic_category()</code>.
</del>
<br/>
<ins>
-1- <i>Effects</i>:
Initializes <code>val_</code> with <code>0</code>
and <code>cat_</code> with <code>&amp;generic_category()</code>.
</ins>
</p>

<pre>error_condition(int val, const error_category&amp; cat) noexcept;</pre>
<p>
<del>
-2- <i>Postconditions</i>:
<code>val_ == val</code> and <code>cat_ == &amp;cat</code>.
</del>
<br/>
<ins>
-2- <i>Effects</i>:
Initializes <code>val_</code> with <code>val</code>
and <code>cat_</code> with <code>&amp;cat</code>.
</ins>
</p>

<pre>template&lt;class ErrorConditionEnum&gt;
  error_condition(ErrorConditionEnum e) noexcept;</pre>
<p>-3- <i>Constraints</i>:
<code>is_error_condition_enum_v&lt;ErrorConditionEnum&gt;</code> is <code>true</code>.
</p>
<p>
<del>
-4- <i>Postconditions</i>:
<code>*this == make_error_condition(e)</code>.
</del>
<br/>
<ins>
-4- <i>Effects</i>: Equivalent to:
</ins>
<blockquote><pre><ins>error_condition ec = make_error_condition(e);
assign(ec.value(), ec.category());
</ins></pre></blockquote>
</p>
</blockquote>
</li>

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

<blockquote>
<pre>template&lt;class ErrorConditionEnum&gt;
  error_condition&amp; operator=(ErrorConditionEnum e) noexcept;</pre>
<p>-2- <i>Constraints</i>:
<code>is_error_condition_enum_v&lt;ErrorConditionEnum&gt;</code> is <code>true</code>.
</p>
<p>
<del>
-3- <i>Postconditions</i>:
<code>*this == make_error_condition(e)</code>.
</del>
<br/>
<ins>
-3- <i>Effects</i>: Equivalent to:
</ins>
<blockquote><pre><ins>error_condition ec = make_error_condition(e);
assign(ec.value(), ec.category());
</ins></pre></blockquote>
</p>
<p>
-4- <i>Returns</i>: <code>*this</code>.
</p>
</blockquote>

</li>

</ul>






</body>
</html>
