<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3367: Integer-class conversions should not throw</title>
<meta property="og:title" content="Issue 3367: Integer-class conversions should not throw">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3367.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++20">C++20</a> status.</em></p>
<h3 id="3367"><a href="lwg-defects.html#3367">3367</a>. Integer-class conversions should not throw</h3>
<p><b>Section:</b> 24.3.4.4 <a href="https://wg21.link/iterator.concept.winc">[iterator.concept.winc]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2020-01-07 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#iterator.concept.winc">issues</a> in [iterator.concept.winc].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
It's widely established that neither conversions of integral types to <code>bool</code> nor conversions 
between different integral types throw exceptions. These properties are crucial to supporting exception 
guarantees in algorithms, containers, and other uses of iterators and their difference types. 
Integer-class types must provide the same guarantees to support the same use cases as do integer types.
</p>

<p><i>[2020-01-14; Daniel comments]</i></p>

<ol>
<li><p>We probably need to think about providing the stronger guarantee that all integer-class operations 
are also <code>noexcept</code> in addition to the guarantee that they do not throw any exceptions.</p></li>
<li><p>The fixed wording in LWG <a href="lwg-defects.html#3358" title="&sect;[span.cons] is mistaken that to_address can throw (Status: C++20)">3358</a><sup><a href="https://cplusplus.github.io/LWG/issue3358" title="Latest snapshot">(i)</a></sup>, 23.7.2.2.2 <a href="https://wg21.link/span.cons">[span.cons]</a> p9 depends on the no-throw-guarantee 
of integer-class conversions to integral types.</p></li>
</ol>

<p><i>[2020-01-25 Status set to Tentatively Ready after five positive votes on the reflector.]</i></p>



<p id="res-3367"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4842">N4842</a>.</p>

<ol>
<li><p>Modify 24.3.4.4 <a href="https://wg21.link/iterator.concept.winc">[iterator.concept.winc]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> There's a bit of drive-by editing here to change occurrences of the meaningless 
"type is convertible to type" to "expression is convertible to type". Paragraph 7 only has drive-by edits. ]
</p>
</blockquote>

<blockquote>
<p>
-6- <del>All</del><ins>Expressions of</ins> integer-class type<del>s</del> are explicitly convertible to 
<del>all</del><ins>any</ins> integral type<del>s and</del><ins>. Expressions of integral type are both</ins>
implicitly and explicitly convertible <del>from all integral types</del><ins>to any integer-class type. 
Conversions between integral and integer-class types do not exit via an exception</ins>.
<p/>
-7- <del>All</del><ins>Expressions <code><i>E</i></code> of</ins> integer-class type<del>s</del> <ins><code>I</code></ins> 
are contextually convertible to <code>bool</code> as if by <code>bool(<del>a</del><ins><i>E</i></ins> != I(0))</code><del>, 
where <code>a</code> is an instance of the integral-class type <code>I</code></del>.
</p>
</blockquote>

</li>
</ol>





</body>
</html>
