<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3174: Precondition on is_convertible is too strong</title>
<meta property="og:title" content="Issue 3174: Precondition on is_convertible is too strong">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3174.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="3174"><a href="lwg-active.html#3174">3174</a>. Precondition on <code>is_convertible</code> is too strong</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> Casey Carter <b>Opened:</b> 2018-12-09 <b>Last modified:</b> 2019-03-16</p>
<p><b>Priority: </b>3
</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>
Per <a href="http://eel.is/c++draft/meta.rel#tab:type-traits.relationship">Table 49</a>
in 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a>, the preconditions for both
<code>is_convertible&lt;From, To&gt;</code> and
<code>is_nothrow_convertible&lt;From, To&gt;</code> are:
</p>
<blockquote>
<p>
<code>From</code> and <code>To</code> shall be complete types, arrays of unknown bound,
or <i>cv</i> <code>void</code> types.
</p>
</blockquote>
<p>
Consequently, this program fragment:
</p>
<blockquote>
<pre>
struct S;
static_assert(is_convertible_v&lt;S, const S&amp;&gt;);
</pre>
</blockquote>
<p>
has undefined behavior despite that the actual behavior of <code>is_convertible</code>
specified in <a href="https://wg21.link/meta.rel#5">[meta.rel]/5</a>:
</p>
<blockquote>
<p>
-5- The predicate condition for a template specialization
<code>is_convertible&lt;From, To&gt;</code> shall be satisfied if and only if the
return expression in the following code would be well-formed, including any
implicit conversions to the return type of the function:
</p>
<blockquote>
<pre>
To test() {
  return declval&lt;From&gt;();
}
</pre>
</blockquote>
<p>[ <i>Note:</i> &hellip;]</p>
</blockquote>
<p>
is well-formed: <code>declval&lt;S&gt;()</code> is an xvalue of type <code>S</code>,
which certainly does implicitly convert to <code>const S&amp;</code>. We should
relax the precondition to allow this perfectly valid case (and similar cases
like <code>is_convertible&lt;S, S&amp;&amp;&gt;</code>), letting the cases that
would in fact be invalid fall through to the blanket "incompletely-defined
object type" wording in
<a href="https://wg21.link/meta.rqmts#5">[meta.rqmts]/5</a>.
</p>

<p><i>[2018-12-21 Reflector prioritization]</i></p>

<p>Set Priority to 3</p>


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

<ol>
<li><p>Modify Table 49 in 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> as follows:</p>
<table border="1">
<caption>Table 49 &mdash; Type relationship predicates</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>
<del><code>From</code> and</del> <code>To</code> shall be <ins>a</ins><br/>
complete type<del>s</del>, <ins>an</ins><br/>
array<del>s</del> of unknown bound,<br/>
or <i>cv</i> <code>void</code> <del>types</del>.
</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 the<br/>
conversion, as defined by<br/>
<code>is_convertible</code>, is known<br/>
not to throw any<br/>
exceptions (7.6.2.7 <a href="https://wg21.link/expr.unary.noexcept">[expr.unary.noexcept]</a>)
</td>
<td>
<del><code>From</code> and</del> <code>To</code> shall be <ins>a</ins><br/>
complete type<del>s</del>, <ins>an</ins><br/>
array<del>s</del> of unknown bound,<br/>
or <i>cv</i> <code>void</code> <del>types</del>.
</td>
</tr>
<tr>
<td>[&hellip;]</td>
<td>[&hellip;]</td>
<td>[&hellip;]</td>
</tr>
</table>
</li>
</ol>





</body>
</html>
