<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4028: std::is_(nothrow_)convertible should be reworded to avoid dependence on the return statement</title>
<meta property="og:title" content="Issue 4028: std::is_(nothrow_)convertible should be reworded to avoid dependence on the return statement">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4028.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#New">New</a> status.</em></p>
<h3 id="4028"><a href="lwg-active.html#4028">4028</a>. <code>std::is_(nothrow_)convertible</code> should be reworded to avoid dependence on the <code>return</code> statement</h3>
<p><b>Section:</b> 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2023-12-18 <b>Last modified:</b> 2023-12-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#meta.rel">active issues</a> in [meta.rel].</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.rel">issues</a> in [meta.rel].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The current specification for <code>std::is_convertible</code> is sensitive to the requirements for the <code>return</code> 
statements. As a result, the requirements were accidentally changed by <a href="https://wg21.link/P0135R1" title=" Wording for guaranteed copy elision through simplified value categories">P0135R1</a> and then changed back by 
CWG issue <a href="https://wg21.link/cwg2426">2426</a>. The current revision of <a href="https://wg21.link/P2748" title=" Disallow Binding a Returned Glvalue to a Temporary">P2748</a> also plans to 
change the wording for <code>std::is_convertible</code> to avoid actual behavioral changing.
<p/>
IMO it's better to specify <code>std::is_convertible</code> in a such way that is independent to <code>return</code> statements. 
The proposed resolution matches what mainstream implementations do, and should resolve LWG <a href="lwg-active.html#3400" title="Does is_nothrow_convertible consider destruction of the destination type? (Status: New)">3400</a><sup><a href="https://cplusplus.github.io/LWG/issue3400" title="Latest snapshot">(i)</a></sup> together.
</p>


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

<ol>

<li><p>Modify 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 49 &mdash; Type relationship predicates [tab:meta.rel]</caption>
<tr style="text-align:center">
<th>Template</th>
<th>Condition</th>
<th>Comments</th>
</tr>
<tr>
<td>[&hellip;]</td>
<td>[&hellip;]</td>
<td>[&hellip;]</td>
</tr>
<tr>
<td>
<pre>
template&lt;class From, class To&gt;
struct is_convertible;
</pre>
</td>
<td><i>see below</i></td>
<td>
<code>From</code> and <code>To</code> shall be<br/>
complete types, <code><i>cv</i> void</code>, or arrays of<br/>
unknown bound.
</td>
</tr>
<tr>
<td>
<pre>
template&lt;class From, class To&gt;
struct is_nothrow_convertible;
</pre>
</td>
<td>
<code>is_convertible_v&lt;From,<br/>
To&gt;</code> is <code>true</code> and <del>the</del><br/>
<del>conversion, as defined by</del><br/>
<del><code>is_convertible</code>, is known</del><br/>
<del>not to throw any exceptions</del><br/>
<ins>either both <code>From</code> and <code>To</code><br/>
are <code><i>cv</i> void</code>, or the function call<br/>
expression used for specifying <code>is_convertible</code><br/>
is non-throwing</ins> (7.6.2.7 <a href="https://wg21.link/expr.unary.noexcept">[expr.unary.noexcept]</a>)
</td>
<td>
<code>From</code> and <code>To</code> shall be<br/>
complete types, <code><i>cv</i> void</code>, or arrays of<br/>
unknown bound.
</td>
</tr>
<tr>
<td>[&hellip;]</td>
<td>[&hellip;]</td>
<td>[&hellip;]</td>
</tr>
</table>

<p>
-5- The predicate condition for a template specialization <code>is_convertible&lt;From, To&gt;</code> 
shall be satisfied if and only if <del>the return expression in the following code would be well-formed, 
including any implicit conversions to the return type of the function:</del>
</p>
<blockquote><pre>
<del>To test() {
  return declval&lt;From&gt;();
}</del>
</pre></blockquote>
<p>
<ol style="list-style-type: none">
<li><p><ins>(?.1) &mdash; either both <code>From</code> and <code>To</code> are <code><i>cv</i> void</code>, or</ins></p></li>
<li><p><ins>(?.2) &mdash; <code>To</code> is neither array nor function type and the function call expression 
<code><i>conv-dest</i>(declval&lt;From&gt;())</code> would be well-formed when treated as an unevaluated operand, 
where <code><i>conv-dest</i></code> is a hypothetical function declared as</ins></p>
<blockquote><pre>
<ins>void <i>conv-dest</i>(To) noexcept;</ins>
</pre></blockquote>
<p>
<ins>.</ins>
</p>
</li>
</ol>
<p/>
[<i>Note 2</i>: This requirement gives well-defined results for reference types, array types, function types, 
and <i>cv</i> <code>void</code>. &mdash; <i>end note</i>]
<p/>
Access checking is performed in a context unrelated to <code>To</code> and <code>From</code>. Only the validity of the 
immediate context of the expression of the <del>return statement (8.8.4 <a href="https://wg21.link/stmt.return">[stmt.return]</a>)</del>
<ins>function call expression (7.6.1.3 <a href="https://wg21.link/expr.call">[expr.call]</a>)</ins> (including initialization of the 
<del>returned</del><ins>parameter</ins> object or reference) is considered.
</p>
</blockquote>
</li>

</ol>







</body>
</html>
